这里的目的是根据我的偏好显示或隐藏下面的div元素
<div ng-repeat="data_training in data.training track by $index">
<h4 ng-hide="data_training.list == [] && data_training.note == '' ">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>
{{data_training.note}}
<ul ng-repeat="data_training_lists in data_training.list track by $index ">
<li>
{{data_training_lists}}
</li>
</ul>
</div>
这只是我的index.html的片段,下面是我的json数据的片段
"training": [
{
"note": "",
"list": [
"Agricultural extension officers ",
"Agricultural shops ",
"Non Government Organisations, Community Based Organisations ",
"Other farmers "
]
}
],
想要显示h4元素,如果只有training.note或training.list对它们有价值。感谢提前
答案 0 :(得分:1)
检查长度&gt; 0:
<h4 ng-hide="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>
答案 1 :(得分:0)
试试这个
<h4 ng-if="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>
或ng-show
<h4 ng-show="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>
或ng-hide
<h4 ng-hide="data_training.list.length && data_training.note.length">WHAT TYPE OF TRAINING IS REQUIRED TO START THIS VENTURE</h4>
我更喜欢使用ng-if
而不是ng-show
ng-if指令从页面中删除内容 ng-show / ng-hide使用CSS显示属性隐藏内容。