使用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>
它似乎不起作用,我该怎么做?
答案 0 :(得分:35)
您需要将消息数组插入$ 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>