Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  146] [ 7]  / answers: 1 / hits: 31927  / 11 Years ago, tue, december 3, 2013, 12:00:00

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?


More From » angularjs

 Answers
16

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



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

[#73927] Sunday, December 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
malaysias

Total Points: 619
Total Questions: 110
Total Answers: 107

Location: Czech Republic
Member since Thu, Aug 11, 2022
2 Years ago
;