仅显示ng-repeat的第一个元素 [英] Only show first element of ng-repeat

查看:201
本文介绍了仅显示ng-repeat的第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何只显示第一个角元素?

How do I show only the first element in angular?

我正在这样使用ng-repeat:

<div ng-repeat="product in products" ng-show="$first">
    <div>{{ product.price }}</div>
</div>

但是由于我没有重复,所以我不必使用ng-repeat吗?我如何才能只显示第一个,而不必进行ng-repeat?

But since I'm not repeating, then I shouldn't have to use ng-repeat? How can I get this to display just the first, without having to go in a ng-repeat?

推荐答案

不要使用ng-repeat指令,这应该可以:

Don't use ng-repeat directive, this should work:

<div>{{ products[0].price }}</div>

这篇关于仅显示ng-repeat的第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆