Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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>
share|improve this answer

Just do:

{{first.second.status || "None"}}
share|improve this answer
    
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? –  raju May 28 '14 at 17:06
    
Probably going to have to use a method to resolve the correct href –  tymeJV May 28 '14 at 17:10
    
take a look at ng-if –  MichaelLo May 28 '14 at 17:12
    
@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. –  Marc Kline May 28 '14 at 17:13
    
I want to remove the href not hide the entire element. –  raju May 28 '14 at 17:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.