Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://pln kr.co/edit/dhKztoIlzoQMi7wpJwbH?p=preview
- <!DOCTYPE html>
- <html>
- <head>
- <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
- </head>
- <body ng-app="myApp">
- <div ng-controller="myCtrl as ctrl">
- <collection list="testdata"></collection>
- </div>
- </body>
- <script>
- angular.module('myApp',[])
- .controller('myCtrl', myCtrl)
- .directive('collection', ['$compile', collection]);
- function collection($compile) {
- return {
- restrict: 'E',
- //template: template,
- scope: {
- list: '='
- },
- transclude:true,
- link: linker
- };
- }
- var linker = function(scope, element, attrs) {
- var template = '<ul>';
- template += '<li ng-repeat="item in list">';
- template += '<span ng-bind="item.TagName"></span>';
- template += '<collection list="item.children"></collection>';
- template += '</li>';
- template += '</ul>';
- if (scpoe.children.length > 0) {
- template = 'template1'
- } else {
- template = 'template2'
- }
- element.html(template);
- $compile(element.contents())(scope);
- }
- function myCtrl($scope) {
- $scope.testdata = [{"TagName":"MyRootNode","TagPath":">MyRootNode","children":[{"TagName":"LandXML","TagPath":">MyRootNode>ChildItems>LandXML","children":[{"TagName":"Units","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Units","children":[{"TagName":"Imperial","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[1]>Imperial","children":[]},{"TagName":"Project","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Project","children":[]},{"TagName":"Application","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Application","children":[{"TagName":"Author","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[2]>Author","children":[]},{"TagName":"Alignments","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Alignments","children":[]},{"TagName":"Roadways","TagPath":">MyRootNode>ChildItems>ChildItems[1]>Roadways","children":[{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[1]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[2]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[3]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[4]","children":[]},{"TagName":"Roadway","TagPath":">MyRootNode>ChildItems>ChildItems[1]>ChildItems[3]>Roadway[5]","children":[]}]}]}]}]},{"TagName":"Surfaces","TagPath":">MyRootNode>ChildItems>Surfaces","children":[{"TagName":"Surface1","TagPath":">MyRootNode>ChildItems>ChildItems[2]>Surface1","children":[]},{"TagName":"Surface2","TagPath":">MyRootNode>ChildItems>ChildItems[2]>Surface2","children":[]}]}]}]
- }
- </script>
- </html>
Add Comment
Please, Sign In to add comment