【发布时间】:2016-06-17 10:19:29
【问题描述】:
我有以下对象列表:
[
{ "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,仅当此对象键(及其值)可用时?
【问题讨论】:
标签: javascript angularjs