change the font color based on value angular js

后端 未结 4 913
既然无缘
既然无缘 2020-12-29 09:32

I am using AngularJS and I use ng-repeat to loop and show the details in the page.

Is there a possibility to change the font color based on the value?

4条回答
  •  太阳男子
    2020-12-29 10:17

    See this example

    var myApp = angular.module('myapp',[]);
    
    myApp
        .controller('MyCtrl1', function ($scope) {
            $scope.vm = {
                States: [
                    {
                        Name: 'Error',
                        state: 'error',
                        color: 'red'
                    },
                    {
                        Name: 'Warning',
                        state: 'warning',
                        color: 'blue'
                    },
                    {
                        Name: 'Ignored',
                        state: 'ignored',
                        color: 'green'
                    }
                ]
            };
        })
    .red{
        color: red;
    }
    
    .blue{
        color: blue;   
    }
    
    .green{
        color: green;
    }
    
    
    
  • {{s.Name}} - {{s.state}}
提交回复
热议问题