我想要实现的是仅在JSON对象中的元素值不等于空字符串时才显示和元素''.
说我有以下json对象
{
'id' : 23,
'name' : 'Adrian Reese',
'age' : '',
'location' : ''
}
Run Code Online (Sandbox Code Playgroud)
现在在部分模板中,我显示用户信息,我做了类似的事情:
<h1>{{ user.name | capitalize }}</h1>
<span class="age">Age: {{ user.age }}</span>
<span class="location">Location: {{ user.location }}</span>
Run Code Online (Sandbox Code Playgroud)
对于每个用户,我希望<span>'s只有在值不等于时才能看到''.我怎样才能实现这一目标?
Pir*_*ran 10
使用ngShow:http://docs.angularjs.org/api/ng.directive:ngShow
<span ng-show="user.age != ''" class="age">Age: {{ user.age }}</span>
<span ng-show="user.location != ''" class="location">Location: {{ user.location }}</span>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15278 次 |
| 最近记录: |