2014-10-08 111 views
-1

我有以下代碼:AngularJS ngRepeat循環變量

$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來獲取文本和每個對象的鏈接範圍鏈接裏面的變量,是有可能這樣做那?

謝謝。

+1

肯定。嘗試嘗試。 – 2014-10-08 09:50:29

+2

@Nabila這是非常基本的東西,只需看看[ngRepeat文檔](https://docs.angularjs.org/api/ng/directive/ngRepeat),你就可以把它排除。 – Bema 2014-10-08 09:52:51

+0

-1沒有研究努力 – AlexFoxGill 2014-10-08 10:16:55

回答

2

看到這是如何工作的:

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

感謝它的工作原理 – Nabila 2014-10-08 10:19:11

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>