Ng-style with condition

后端 未结 7 1493
旧巷少年郎
旧巷少年郎 2021-01-11 09:25

How can I apply style on some item in a list that satisfy listed condition:

        
相关标签:
7条回答
  • 2021-01-11 10:24

    You can use this method described further here. (example below)

    angular.module('app', []); 
    function myCtrl($scope){
       $scope.items = [
         { name: 'a', selected: 'false' },
         { name: 'b', selected: 'true' }
       ];
    }
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
    <html ng-app>
      <body ng-controller="myCtrl">
        <div ng-repeat="item in items">
          <div ng-style="{color: {true:'red'}[item.selected]}">{{item.name}}</div>
        </div>
      </body>
    </html>

    0 讨论(0)
提交回复
热议问题