AngularJS ngRepeat循环变量

时间:2014-10-08 09:46:09

标签: javascript angularjs loops angularjs-ng-repeat

我有以下代码:

 $scope.links = { 
            home: {text:'Home', link:'#'},
            about: {text:'Contact', link:'#'},
            handeMade: {text:'Contact', link:'#'},
            shirts: {text:'Contact', link:'#'},
            design: {text:'Contact', link:'#'},
            photography: {text:'Contact', link:'#'},
            blog: {text:'Contact', link:'#'},
            contact: {text:'Contact', link:'#'}
        }

我想使用指令ngRepeat在范围链接中循环变量来获取每个对象的文本和链接,是否可以这样做?

感谢。

2 个答案:

答案 0 :(得分:2)

了解其工作原理:

<div ng-repeat="link in links track by $index">
    <p>Text: {{link.text}}</p>
    <p>Link: {{link.link}}</p>
</div>

答案 1 :(得分:0)

<div ng-repeat="(key,value) in links">
  <div ng-repeat="(k,v) in value">
     <p>Text: {{k.text}}</p>
     <p>Link: {{k.link}}</p>
   </div>
</div>