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

16,370

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

Share:
16,370
user3812457
Author by

user3812457

Updated on June 15, 2022

Comments

  • user3812457
    user3812457 almost 2 years

    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.

  • user3812457
    user3812457 almost 10 years
    The value is not hard coded ,either true or false value coming to variable from json data dynamically
  • user3812457
    user3812457 almost 10 years
    i want to change the true to yes at line no .24 in the plunker [link](plnkr.co/edit/N1wtkAHnnKA77gI6YW4D?p=preview )
  • mainguy
    mainguy almost 10 years
    Errm, where is the ng-grid in this example?
  • mainguy
    mainguy almost 10 years
    Anyhow, filter works here too. plnkr.co/edit/sTYo8hSIwYYnhX2YfKVU?p=preview I allowed myself to clean up your messy example. Please read some tutorials about angular before continuing to ask questions. And make the TOUR in the HELP menu at the top of this page to learn how to ask questions. This might spare you the downvotes.
  • user3812457
    user3812457 almost 10 years
    thank you for your suggestions ,ng-grid is my work space ,i want to explain my situation i used that plunker ,is there any ng-if condition based solution to transfer the dynamic data true to yes based on condition .
  • user3812457
    user3812457 almost 10 years
    thank you for your suggestions ,i am expecting ng-if type solution to convert the true to yes based on condition .if possible please send your answer
  • sylwester
    sylwester almost 10 years