我是AngularJs的新手并且使用ng-init和ng-repeat来完成一个无法正常工作的示例。这是我身体代码的一部分
<div ng-app="" ng-init="books=[
{title:'Pride and Prejudice', author:'Jane Austen', genre:'Romance'}
{title:'Dracula', author:'Bram Stoker', genre:'Horror'}
{title:'The Hobbit', author:'J.R.R. Tolkien', genre:'Fantasy'}
]">
<p>Here are your books:</p>
<ol>
<li ng-repeat="book in books">
{{ 'Title: ' + book.title + ', Author: ' + book.author + ', Genre: ' + book.genre }}
</li>
</ol>
</div>
如果删除Dracula和The Hobbit的行,数据会显示,但所有三本书都没有显示数据。
答案 0 :(得分:1)
您缺少用于分隔数组项的逗号。
<div ng-app="" ng-init="books=[
{title:'Pride and Prejudice', author:'Jane Austen', genre:'Romance'},
{title:'Dracula', author:'Bram Stoker', genre:'Horror'},
{title:'The Hobbit', author:'J.R.R. Tolkien', genre:'Fantasy'}
]">
<p>Here are your books:</p>
<ol>
<li ng-repeat="book in books">
{{ 'Title: ' + book.title + ', Author: ' + book.author + ', Genre: ' + book.genre }}
</li>
</ol>
</div>
[element0,element1,...,elementN]