我有以下对象列表:
[
{ "name" : "foo", "description" : "description of foo..." },
{ "name" : "bar", "description" : "description of bar..." },
{ "name" : "baz" },
...
]
所有对象都有一个name
,但有些对象有一个关联description
,其余的则没有。
我使用下面的模板,将一个input
字段连接到typeahead,以显示每个匹配的对象:
<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
return会解析错误。
仅当此对象键(及其值)可用时,才应使用ng-show
或其他指令呈现description
?
<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="match.model.description">{{match.model.description}}</span>
</a>
</script>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句