angular.js - How to add color to text with angularjs's custom filter?
ringa_lee
ringa_lee 2017-05-15 17:01:58
0
1
485

This is the filter:

app.filter('ifLogin', function () {

    return function (target) {


        if (target == "0") {

            return "在职";

        } else {

            return "离职";

        }

    }

});

This is the realistic part:

<tr ng-repeat="x in datas">
                    <td>{{ x.id }}</td>
                    <td>{{ x.corp}}</td>
                    <td>{{ x.department }}</td>
                    <td>{{ x.status|ifLogin }}</td>
                </tr>

Show the results:

Question, if you want to display green when you are employed, and red when you are out of work! ! ! ? ?
Is there any convenient way to do this in angular?

ringa_lee
ringa_lee

ringa_lee

reply all(1)
小葫芦

For this requirement, it is not suitable to use filters for the color part. It is more convenient to use ng-class或者ng-style, for example:

<tr ng-repeat="x in datas">
    <td>{{ x.id }}</td>
    <td>{{ x.corp}}</td>
    <td>{{ x.department }}</td>
    <td ng-style="{color: x.status === '0' ? 'green' : 'red'}">{{ x.status |ifLogin }}</td>
</tr>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template