2015-11-03 23 views
-1

這必須是一個非常愚蠢的問題;然而,我正在學習角度,並認爲我有一切工作,但事實並非如此。ng-repeat和json不會顯示在li的子頁面中

我沒有通過終端或控制檯收到任何錯誤。我的第一個李的列表正在顯示。我試圖讓下面的子頁面填充;但是,我什麼也沒有得到。

下面是HTML:

<nav class="menu-wrap"> 
     <ul> 
     <li ng-repeat="link in links" ng-class="{true: 'dropDown'}[dropDown]"> 
      <a ng-href="{{link.href}}"> 
      <i class="{{link.icon}}"></i> 
      {{link.name}} 
      <span class="{{link.arrowDown}}" ng-click="dropDown != dropDown"></span> 
      </a> 
      <ul> 
      <li ng-repeat="child in links.child"> 
       <a ng-href="{{links.child.href}}"> 
       <i class="{{links.child.icon}}"></i> 
       {{links.child.name}} 
       </a> 
      </li> 
      </ul> 
     </li> 
     </ul> 
    </nav> 

控制器:

angular.module('App') 
.controller('PrimaryMenuCtrl', function ($scope) { 

    // Set menu to closed 
    $scope.open = false; 
    $scope.dropDown = false; 

    // Toggle open class on click 
    $scope.toggle = function() { 
     $scope.open = !$scope.open; 
     $scope.dropDown = !$scope.dropDown; 
    }; 

    $scope.links = [{ 
     name: 'Dashboard', 
     icon: 'fa fa-user', 
     href: '#', 
     arrowUp: 'fa fa-angle-up', 
     arrowDown: 'fa fa-angle-down', 
     child: [{ 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }, { 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }, { 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }] 
    }, { 
     name: 'Post', 
     icon: 'fa fa-user', 
     href: '#' 
    }, { 
     name: 'Media', 
     icon: 'fa fa-user', 
     href: '#' 
    }, { 
     name: 'Pages', 
     icon: 'fa fa-user', 
     href: '#' 
    }, { 
     name: 'Comments', 
     icon: 'fa fa-user', 
     href: '#', 
     arrowUp: 'fa fa-angle-up', 
     arrowDown: 'fa fa-angle-down', 
     child: [{ 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }, { 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }, { 
      name: 'Child Page', 
      icon: 'fa fa-user', 
      href: '#' 
     }] 
    }, { 
     name: 'Appearance', 
     icon: 'fa fa-user', 
     href: '#' 
    }, { 
     name: 'Plugins', 
     icon: 'fa fa-user', 
     href: '#' 
    }, { 
     name: 'Users', 
     icon: 'fa fa-user', 
     href: '#' 
    }]; 

}); 

回答

1

嘗試使用link.child代替links.child在NG重複和都使用,而不是links.child.X child.X角度表達式

+0

我是白癡,你是對的。 – zach57

1

孩子是鏈接實例的屬性

轉換這個

ng-repeat="child in links.child" 

這個

ng-repeat="child in link.child" 

子部分的全部代碼

<li ng-repeat="child in link.child"> 
       <a ng-href="{{child.href}}"> 
       <i class="{{child.icon}}"></i> 
       {{child.name}} 
       </a> 
      </li> 
+0

借調 - 原因是「鏈接」在父級ng中定義 - 重複 –

1
<nav class="menu-wrap"> 
    <ul> 
    <li ng-repeat="link in links" ng-class="{true: 'dropDown'}[dropDown]"> 
     <a ng-href="{{link.href}}"> 
     <i class="{{link.icon}}"></i> 
     {{link.name}} 
     <span class="{{link.arrowDown}}" ng-click="dropDown != dropDown"></span> 
     </a> 
     <ul> 
     <li ng-repeat="child in links.child"> 
      <a ng-href="{{child.href}}"> 
      <i class="{{child.icon}}"></i> 
      {{child.name}} 
      </a> 
     </li> 
     </ul> 
    </li> 
    </ul> 
</nav> 
+0

請將您的nav html更改爲上面的一個。 – Mitul