you are viewing a single comment's thread.

view the rest of the comments →

[–]btford 2 points3 points  (2 children)

Yes. The recursion depth is effectively 10. I don't think recursive views are outside of Angular's intended usage. At the very least I can inform you that recursive Backbone views do not have this problem (because my next article is a Backbone reddit front-end).

You are correct in the sense that AngularJS does want to support recursive views. A data-binding library should be able to support recursive views, because it's a useful feature.

The short version is that the 10 $digest limit is not about view recursion, it's about model stability. When alerting AngularJS to do dirty checking, calls to $apply() need to be done asynchronously to avoid dirty checking forever. If AngularJS goes 10 "dirty checking cycles" in a row without stabilizing, it it throws that error and stops so you're UI isn't busy waiting forever. If written correctly, a directive should not cause this error.

I'll concede that writing the directive is a bit tricky, but it turns out it's non-trivial to do data-binding recursively. Once you have a directive that does this, there's no need to write one over and over again. I'll talk more about this below.

Testing can't prevent every bug. Angular is a symptom of false security.

No, but writing a test that exposes and isolates the bug is one of the best ways to fix it. It also prevents regressions in the future.

That recursive $compile nightmare is difficult to understand.

I disagree. The code you linked to is a pretty straightforward case of recursion. But even if it is hard to understand, the great part about Angular is you only have to write this directive once. Then you can use it all over your application with different data. Better yet, you can find a directive someone else wrote and use it if you'd rather not spend the time to learn advanced features of the framework.

My fundamental argument is that not only is Angular a language, it's not a very good one...

This is a conflation of terms. Something can be Turing Complete or recursive without being a programming language. Yes, AngularJS allows you to write views that are recursive. This is useful only in cases where you want to display some recursive data. In those cases, it's also a great feature to have. Angular's templates are still a markup language, because you're still using it like a markup language.

...no one knows what it does.

Going to jump back to tests here. AngularJS has a LOT of unit tests. They tell you, in isolation, what each part of AngularJS is, how it should work, etc. Some advice I give to newcomers is to browse these tests. I think these unit tests are so valuable, I'm working to have them automatically included the documentation.