Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular apply style to the first visible item in ngRepeat

I have a list generated by ngRepeat, like so

<ul class="list-group">
    <li class="list-group-item" ng-repeat="data in tree | filter:key">
        {{data.name}}
    </li>
</ul>

and I want the first item in the list to have rounded corners. I have a style such as

.first-item {
  border-top-left-radius: 15px;
  border-top-right-radius: 15px;
}

How can I cause this style to be applied to the first visible item? Note that the key is connected to a search box, so the first item is dynamic.

like image 493
John Henckel Avatar asked Jan 17 '26 22:01

John Henckel


2 Answers

use $first, that represents the first iteration within a ng-repeat

<ul class="list-group">
    <li ng-class="{'first-item':$first}"
class="list-group-item" ng-repeat="data in tree | filter:key">
        {{data.name}}
    </li>
</ul>      

edit: since first-item has a dash, it must be in quotes

like image 150
Sasi Kiran Avatar answered Jan 20 '26 14:01

Sasi Kiran


You can use the css rule first-child:

.list-group li:first-child { 
     border-top-left-radius: 15px;
     border-top-right-radius: 15px;
}

http://www.w3schools.com/cssref/sel_firstchild.asp

like image 23
FakeSkdr Avatar answered Jan 20 '26 13:01

FakeSkdr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!