我想隐藏每个使用ng-hide指令的没有内容的标签(简单文本)。 下面是我想要实现的:
<div class="menu-head" ng-hide="c1.section == ''">{{c1.section}}</div>
但是这不起作用。然而,下面的两个评估为真(用于测试目的我设置c1.section字段的“第1”的值)和相应的div变为隐藏的:
<div class="menu-head" ng-hide="c1.section == c1.section">{{c1.section}}</div>
<div class="menu-head" ng-hide="c1.section == 'Section 1'">{{c1.section}}</div>
的c1.section是经由如何在标签为空时隐藏标签(不包含文本)
<div ng-repeat="c1 in col1">
访问从该控制器:
function MenuCtrl($scope) {
"use strict";
$scope.col1 = MenuData.col1;
$scope.col2 = MenuData.col2;
$scope.col3 = MenuData.col3;
}
当对象COL1可以,或可以不包含字段 '部分'。所以很明显,无论何时从对象中缺少一个字段(任何字段),我都希望它的div在DOM中丢失/不显示。这里的MenuData对象:
var MenuData = {
col1: [
{section: 'Section 1'}, // <-here the fields id, name, price and descr are missing so their divs must not show up in the DOM.
{
id: '1',
// section: 'Section 2', <- here the field section is missing (commented-out).
name: 'Position 1',
price: '2.50',
descr: 'some description'
},
{section: 'Section 3'},
{
id: '2',
section: 'Section 4',
name: 'Position 2',
price: '4.75',
descr: ''
}
]
};
我如何NG隐藏的表达,以评估为“真”时,有在“c1.section”数据绑定没有内容?
什么是'c1.section'?你最初设定的是什么?它是'空字符串'还是可能未定义? –
你可以用'ng-show'来代替吗? – imaginaryboy
@BenjaminGruenbaum我已经更新了我的问题。 –