-->

How to display Yes/No instead of True/False in Ang

2019-02-19 06:50发布

问题:

I am using the cellTemplate to display the data in grid ,now i have to display the data in ng-grid ,where i can display the data containing true or false value in one column ,please guide me how to display the true or false data like yes or no ,i.e ,for true value i have to display yes and for false value to no .please guide me what changes in makes my required result.

回答1:

Create a simple filter like:

app.filter('true_false', function() {
    return function(text, length, end) {
        if (text) {
            return 'Yes';
        }
        return 'No';
    }
});

and use it in your cellTemplate (or wherever you want):

cellTemplate: '<div class="ngCellText">{{row.getProperty(col.field) | true_false}}</div>'

Here is a Plunker



回答2:

You can add ng-options in your tag

ng-options="myMethod(item) for item in [true, false]"

Then define

$scope.myMethod = function(arg) {return arg ? 'Yes' : 'No'};


回答3:

Hi Please see here: http://jsbin.com/bogir/1/edit?html,js

  <span ng-show="model">true</span>
  <span ng-hide="model">false</span>