简体   繁体   中英

How to set default value for scope variable in angularjs

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?

做就是了:

{{first.second.status || "None"}}

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM