wes*_*bos 26 javascript angularjs
使用ng-repeat,我将如何循环以下内容:
var messages : [
{text:"Standard Message"},
{text:"Success Message!", type:"success"},
{text:"Alert Message!", type : "alert"},
{text:"secondary message...", type : "secondary"}
]
Run Code Online (Sandbox Code Playgroud)
我试过了:
<p ng-repeat="message in messages">{{message}}</p>
Run Code Online (Sandbox Code Playgroud)
它似乎不起作用,我该怎么做?
Dor*_*hen 36
您需要将消息数组插入$ scope:
$scope.messages = [
{text:"Standard Message"},
{text:"Success Message!", type:"success"},
{text:"Alert Message!", type : "alert"},
{text:"secondary message...", type : "secondary"}
]
Run Code Online (Sandbox Code Playgroud)
然后使用它如下:
<p ng-repeat="message in messages">{{message.text}}</p>
Run Code Online (Sandbox Code Playgroud)