How to apply if and else angularjs controller

I have HTML code

 <li><strong>Scrub:</strong> {{insuredProfile.permanentAddress.isScrubbed}}</li>

This display is true or false. I need to show Yes for true and No for false.

If I use data-ng, if I can only apply one condition at a time. Can anyone suggest a better way to do this. thank

+3
source share
2 answers

The easiest way is likely to use the built-in if:

{{insuredProfile.permanentAddress.isScrubbed ? 'Yes' : 'No'}}

Edited according to the comments, sorry for the typo.

+4
source

You can write a filter that does this.

(function (app) {
    app.filter('boolToYesNo', function () {
        return function (input) {
            return input ? 'yes' : 'no';
        }
    });
})(angular.module('app'));

And then call it like

{{ insuredProfile.permanentAddress.isScrubbed | boolToYesNo }}

+2
source

All Articles