2

I currently display a scope variable using the following code

<a data-ng-href="#!/params/{{first.second.status}}">{{first.second.status}}</a>

Sometimes first.second.status is null, undefined or empty in which case I want to display "None" instead of actual value(empty)

One of the way to achieve the above is to put the check for the value of first.second.status in the controller and change its value accordingly but is there a more elegant way of doing it?

2 Answers 2

14

Just do:

{{first.second.status || "None"}}
Sign up to request clarification or add additional context in comments.

4 Comments

I would also want to remove the href when it is None but have a valid one when it is not None. How do I do that?
Probably going to have to use a method to resolve the correct href
@raju Do you want to remove the href attribute or hide the entire element? If it's the latter, look at ng-if (as @MichaelLo just suggested) or even ng-show/hide.
I want to remove the href not hide the entire element.
4

You could do:

<a ng-if="first.second.status" 
   data-ng-href="#!/params/{{first.second.status}}">{{first.second.status}}</a>
<span ng-if="!first.second.status">None</span>

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.