我有以下对象名单:如何在AngularJS模板中有条件地显示跨度?
[
{ "name" : "foo", "description" : "description of foo..." },
{ "name" : "bar", "description" : "description of bar..." },
{ "name" : "baz" },
...
]
所有的对象都有一个name
,但也有一些相关的description
,其余的则没有。
我使用与连接到一个预输入的input
字段下面的模板,以显示每个匹配的对象:
<script type="text/ng-template" id="my-template.html">
<a style="text-align: left;">
<span style="font-size: 18px; display:block;">{{match.model.name}}</span>
<span ng-show="typeof({{match.model.description}}) !== 'undefined'">{{match.model.description}}</span>
</a>
</script>
我想模板来显示description
只有当它的值被定义,但我的使用的ng-show
返回解析错误。
只有当此对象键(及其值)可用时,我应该如何使用ng-show
或其他指令来渲染description
?
感谢您的回答;这对我来说是正确的。 –