最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set default value for scope variable in angularjs - Stack Overflow

programmeradmin3浏览0评论

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?

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 edited May 28, 2014 at 17:09 raju asked May 28, 2014 at 17:01 rajuraju 5,00817 gold badges66 silver badges121 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 14

Just do:

{{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>
发布评论

评论列表(0)

  1. 暂无评论