Summary:
Recursive directives work without angular post-link recursion plumbing.
Plunker:
Story:
Angular is a very powerful framework. I use it to easily bind my JSON models to client-side views. Only after a hard experience with a project filled with dynamic functionality, complicated data and responsive AJAX stuff in which I hand-baked everything, including generation of HTML elements based on the JavaScript models, I learned that I should use a client MVC framework such as Angular.
I already have ReactJS on my radar while still mastering AngularJS.
The thing today is about recursive directives. I tried it once and got into a lot of trouble, I read online and found out easy ways of using <script> tags as opposed to directives, and another way that uses directives but requires post-compile work (you specify the post-compile or post-link function while defining your directive one your angular module).
I thought to myself that the "Isolated Scopes" that Angular promise directives can have, aren't really isolated if I can't just compose directives in any way that I want, including recursively. I was bugged with the fact so I did more tests and code monkeying (experimentation) to find that recursive actually works without the suggested Recursion Service.
To explore, I started with the most basic scenario and gradually made my scenario more complex. First, a directive, then a directive with complex object, then two directives one calling another, then, finally, a single directive calling itself (recursively).
You can find traces of such gradual increase experimentation complexity. Some variables are no longer used, some directives are defined but also unused in the templates, and finally a recursive directive that is actually used. See the code above for an example.
Recursive directives work without angular post-link recursion plumbing.
Plunker:
Story:
Angular is a very powerful framework. I use it to easily bind my JSON models to client-side views. Only after a hard experience with a project filled with dynamic functionality, complicated data and responsive AJAX stuff in which I hand-baked everything, including generation of HTML elements based on the JavaScript models, I learned that I should use a client MVC framework such as Angular.
I already have ReactJS on my radar while still mastering AngularJS.
The thing today is about recursive directives. I tried it once and got into a lot of trouble, I read online and found out easy ways of using <script> tags as opposed to directives, and another way that uses directives but requires post-compile work (you specify the post-compile or post-link function while defining your directive one your angular module).
I thought to myself that the "Isolated Scopes" that Angular promise directives can have, aren't really isolated if I can't just compose directives in any way that I want, including recursively. I was bugged with the fact so I did more tests and code monkeying (experimentation) to find that recursive actually works without the suggested Recursion Service.
To explore, I started with the most basic scenario and gradually made my scenario more complex. First, a directive, then a directive with complex object, then two directives one calling another, then, finally, a single directive calling itself (recursively).
You can find traces of such gradual increase experimentation complexity. Some variables are no longer used, some directives are defined but also unused in the templates, and finally a recursive directive that is actually used. See the code above for an example.