2016-01-05 55 views
2

我想改變這顯示如下列表中的最後一個元素的顏色最後一個可見的元素,Angularjs發現NG重複

<div ng-repeat="item in items"> 
<h3 ng-hide="(hideStudent && item.role == 'student')" ng-class="{'last':$last}">{{item.name}}</h3> 
</div> 
<button type="button" ng-click="(hideStudent = true)" >Hide Students</button> 

CSS:

.last { 
color: #800; 
} 

當我點擊在「隱藏學生」按鈕上,所有學生都將被隱藏起來。現在,如果最後一個項目是學生,並且它隱藏,那麼最後顯示的元素顏色不會發生變化,因爲$ last似乎不會查看元素是否隱藏。我可以使用ng-if代替ng-hide,但想知道這是否可以用其他方式完成,而不是使用ng-if。

+0

這個問題在本帖(http://stackoverflow.com/q/14581658/4298824) –

+0

只能使用NG-風格回答定義顯示或隱藏項目。然後,你可以使用:last-child選擇最後一個可見項:ng-style =「(hideStudent && item.role =='student')?'hide':'show'」和css .show:last-孩子 –

回答