我正在尝试制作一个博客而我正在使用angularJs。 我在Json文件中有所有文章都是这样的
articles.json
{
"title": "Post One",
"body": [
"First paragraph",
"Second paragraph",
"..."
],
"author": "Author",
"comments": [
{
"body":"Comment no 1",
"author": "AuthorComment"
}
],
"likes":0,
"createdOn": today-date
},
现在,在我的HTML中,我想在顶部显示最新的文章,在另一个div中,我想再添加6篇从最新到最旧的文章(因此它意味着文章从2到7)。
这样的事情:
<div id="newest-article" ng-repeat="post in posts|limitTo:1">
<h1>{{post.title}}</h1>
<p>{{post.body}}</p>
</div>
<div id="list-of-six-posts">
<h1>Post 2</h1>
</p>Body post 2</p>
<h1>Post 3</h1>
</p>Body post 3</p>
<h1>Post 4</h1>
</p>Body post 4</p>
<h1>Post 5</h1>
</p>Body post 5</p>
<h1>Post 6</h1>
</p>Body post 6</p>
<h1>Post 7</h1>
</p>Body post 7</p>
</div>
问题:如何使用ng-repeat来说“从帖子2重复到帖子7”?
答案 0 :(得分:3)
好的,我自己找到了答案。
<div ng-repeat="post in blog.posts" ng-if="$index >=1 && $index<7">
答案 1 :(得分:0)
<强>尊敬的强>,
你可以这样做:
<div id="newest-article" ng-repeat="post in posts|limitTo:1">
<h1>{{post.title}}</h1>
<p>{{post.body}}</p>
</div>
<div id="rest-article" ng-if="$index > 0 ng-repeat="post in posts">
<h1>{{post.title}}</h1>
<p>{{post.body}}</p>
</div>
这将跳过索引0表示您的值将仅从索引1打印在屏幕上。
谢谢&amp;干杯强>