angularjs ng-repeat loop different styles - angularjs ng-repeat loop different styles
给我你的怀抱
给我你的怀抱 2017-05-15 17:13:42
0
3
695

I want to realize that the jump button is red, the delete button is blue, and the add button is white. However, if the current cycle is like this, it will all be in the style of "btn-warning", which is red!

angular.module('demoAPP').controller('demoCtrl', function($scope) {
  var demoData = [
    {
      "Name" : "操作",
      "action" : "跳转"
    },
    {
      "Name" : "操作",
      "action" : "删除"
    }
    {
      "Name" : "操作",
      "action" : "添加"
    }
  ]
  $scope.demo = demoData;
    });

<table>
    <tr ng-repeat="item  in demo">
      <td>{{item.Name}}</td>
      <td><button type="button" class="btn btn-warning">{{item.action}}</button></td>
    </tr>  
</table>
给我你的怀抱
给我你的怀抱

reply all(3)
伊谢尔伦

ng-class should do the trick.

过去多啦不再A梦

ng-class="{'Style':item.action=='Jump'}"
ng-class="{'Style':item.action=='Add'}"
ng-class="{ 'Style':item.action=='Modify'}"
Execute style when ng-class is true

我想大声告诉你

Multiple styles in ng-class are separated by commas, and write all three judgments in the repetition.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template