angularjs - Add a calculated class to an HTML element in angular -
i render bunch of user icons on page. want give them class based on id.
example user object
{ id: 1234, name: "foo" } html element
<div ng-repeat="user in userlist" class="something-{{ user.id % 10 + 1 }}"> </div> so classes "something-1", "something-2", ... based on users id.
the above code doesn't work. no class shows on element. right way this?
please give try ng-init. in case html be
<div ng-repeat="user in userlist" ng-init="myid = (user.id % 10) + 1;" class="something-{{ myid }}"> </div>
Comments
Post a Comment