26

使用 ng-repeat,我将如何遍历以下内容:

var  messages : [
      {text:"Standard Message"},
      {text:"Success Message!", type:"success"},
      {text:"Alert Message!", type : "alert"},
      {text:"secondary message...", type : "secondary"}
    ]

我试过了:

<p ng-repeat="message in messages">{{message}}</p> 

它似乎不起作用,我该怎么做?

4

1 回答 1

38

您需要将消息数组插入 $scope:

$scope.messages = [
      {text:"Standard Message"},
      {text:"Success Message!", type:"success"},
      {text:"Alert Message!", type : "alert"},
      {text:"secondary message...", type : "secondary"}
    ]

然后按如下方式使用它:

<p ng-repeat="message in messages">{{message.text}}</p>
于 2013-06-26T17:59:57.657 回答