在 ng-repeat 中将 class 更改为 angularJS
Change class in angularJS in ng-repeat
我有两个 css classed triangle
和 triangleo
<div class="triangle" ng-repeat="chatdata in chats">
<p>{{chatdata.msg}}</p>
<p> {{chatdata.time}}</p>
</div>
所以 if chatdata.usrId == 123 class 应该是 triangle
else triangleo
你可以简单地使用 ng-class
<div ng-class="chatdata.usrId === 123 ? 'triangle' : 'triangleo'" ng-repeat="chatdata in chats">
<p>{{chatdata.msg}}</p>
<p> {{chatdata.time}}</p>
</div>
我有两个 css classed triangle
和 triangleo
<div class="triangle" ng-repeat="chatdata in chats">
<p>{{chatdata.msg}}</p>
<p> {{chatdata.time}}</p>
</div>
所以 if chatdata.usrId == 123 class 应该是 triangle
else triangleo
你可以简单地使用 ng-class
<div ng-class="chatdata.usrId === 123 ? 'triangle' : 'triangleo'" ng-repeat="chatdata in chats">
<p>{{chatdata.msg}}</p>
<p> {{chatdata.time}}</p>
</div>