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

2019-02-19 06:56发布

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.

3条回答
不美不萌又怎样
2楼-- · 2019-02-19 07:08

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

  <span ng-show="model">true</span>
  <span ng-hide="model">false</span>
查看更多
你好瞎i
3楼-- · 2019-02-19 07:18

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'};
查看更多
Evening l夕情丶
4楼-- · 2019-02-19 07:23

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

查看更多
登录 后发表回答