Created
June 24, 2013 05:36
-
-
Save marufsiddiqui/5847934 to your computer and use it in GitHub Desktop.
Nested directives in angularjs link: http://sporto.github.io/blog/2013/06/24/nested-recursive-directives-in-angular/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.directive('collection', function () { | |
| return { | |
| restrict: "E", | |
| replace: true, | |
| scope: { | |
| collection: '=' | |
| }, | |
| template: "<ul><member ng-repeat='member in collection' member='member'></member></ul>" | |
| } | |
| }); | |
| app.directive('member', function ($compile) { | |
| return { | |
| restrict: "E", | |
| replace: true, | |
| scope: { | |
| member: '=' | |
| }, | |
| template: "<li></li>", | |
| link: function (scope, element, attrs) { | |
| if (angular.isArray(scope.member.children)) { | |
| element.append("<collection collection='member.children'></collection>"); | |
| $compile(element.contents())(scope); | |
| } | |
| } | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment