0

I am getting data in {{insuredProfile.mailingAddress.isScrubbed}} either true or false.I want to convert true to yes and and false to No. I can do this at service side but I want to know is there any way to apply this condition at HTML side.

My code is :

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

3 Answers 3

3

I use this simple filter to do the same:

//converts truthly values to yes, others to no
.filter('yesOrNo',function() {
    return function(val) {
        if(!!val === true) {
            return 'Yes';
        }
        else {
            return 'No';
        }
    }
})

markup

<li><strong>Scrub:</strong> {{insuredProfile.mailingAddress.isScrubbed | yesOrNo}}</li>
Sign up to request clarification or add additional context in comments.

Comments

1

You could write a filter function if you find yourself doing this sort of thing throughout your applicatuib, see

http://docs.angularjs.org/guide/filter

In which case you would just pipe your expression into the filter like so:

<li><strong>Scrub:</strong> {{insuredProfile.mailingAddress.isScrubbed | yesNoify}}</li>

If it's just a one off, you could just but a function on the controllers scope and call it like so:

<li><strong>Scrub:</strong> {{yesNoify(insuredProfile.mailingAddress.isScrubbed)}}</li>

Comments

0

How about just using a ng-show statement:

<li><strong>Scrub:</strong>
    <span ng-show="insuredProfile.mailingAddress.isScrubbed">Yes</span>
    <span ng-show="!insuredProfile.mailingAddress.isScrubbed">No</span>
</li>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.