by jacques_chester · 13y ago · 0 comments
Edit: and yes, I did actually crack open the source to see if I could make that change. In places it's ... pretty densely written. It seems to me that at least checking to see if an array has any elements and aborting if it's empty would go some of the way to stopping the locking-up problem, but I couldn't work out if that was so.
So like everyone else I have a frankenstein pair of directives to achieve the same thing.
It would also be nice if it just did the expected thing out of the box. I can accept that there may well be sound technical reasons for the way it is, but I haven't seen any. All that happens when you raise this limitation is one of three things:
1. "Use ngIf".
2. "Use ngInclude".
3. "Write your own directives".
I tried 1 and 2, that's why I'm on 3.
http://sporto.github.io/blog/2013/06/24/nested-recursive-dir...
I've modified it a bit to add a $watchCollection listener. So when a recursive array is updated, it deletes a child OL and then recompiles again:
https://gist.github.com/jchester/6227865
I don't particularly like the fact that this creates a dependency on jQuery (through .empty()).
There are other approaches where the recursion is sorta-kinda-but-not-really built into a single directive:
https://gist.github.com/furf/4331090
https://github.com/eu81273/angular.treeview
Edit: I guess what I wished for would be something like this --
<div ng-repeat="recursive items in sub_items">{{foo}}</div>
or <div ng-recursive="items in sub_items">{{foo}}</div>
or <div ng-repeat="items in sub_items" ng-recursive>{{foo}}</div>
Whichever is easiest to get into the mainline code.