How to display Yes/No instead of True/False in AngularJS [closed]

人走茶凉 提交于 2019-12-04 01:52:35

问题


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>


来源:https://stackoverflow.com/questions/24611455/how-to-display-yes-no-instead-of-true-false-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!