How do I show only the first element in angular?
I'm using ng-repeat
like this:
<div ng-repeat="product in products" ng-show="$first">
<div>{{ product.price }}</div>
</div>
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?
You might also want to use
<div ng-repeat="product in products|limitTo:1">
<div>{{ product.price }}</div>
</div>
but yes the code below is better
<div>{{products[0].price}}</div
Don't use ng-repeat directive, this should work:
<div>{{ products[0].price }}</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With