change color with ng-style and different conditions

Viewed 15595

I want to parameter changes of color of my td so I try this and it's working fine: {{item.name}}

but when I try to use different conditions for example for

item.name : xxx =>color : red

item.name: yyy =>color : yellow

item.name: aaa =>color : blue

5 Answers

## controllerjs ##

 var app = angular.module("app",[]);

    app.controller("ctrl" , function($scope){
  $scope.Unresolved = [{"status":"Assigned"},{"status":"Unassigned"},{"status":"CustomerWait"}];
  $scope.getStyle = function(status){
    console.log('color============>>>>>>>>>',status);
      if(status == "Unassigned")
        return {'background-color':'#d9534f'};
      if(status == "Assigned")
        return {'background-color':'#337ab7'};
      if(status == "CustomerWait")
        return {'background-color':'green'};
   });

       })

jade

script(src='js/angularjs/angular.js')(you using version)
tr(ng-repeat='unresolved in unresolveds track by $index')
  td
    select.colorSel(ng-model='unresolved.status',ng-style='getStyle(unresolved.status)')
      option(value='Assigned',) Assigned
      option(value='Unassigned') Unassigned
      option(value='Customer wait') Customer wait
Related