我有这样的HTML。
<label ng-if="" for="lblConcat">My label
</label>
<div>
<span ng-bind="model.test1"></span>
<span ng-bind="model.test2"></span>
<span ng-bind="model.test3"></span>
<span ng-bind="model.test4"></span>
</div>
如果至少有一个跨度有值,我想显示/隐藏标签。
我知道我们可以在 Ng-If 中使用多个表达式,但它是用于检查空值和空值的非常冗长的代码。
我们也可以在控制器中创建一个函数并在 Ng-If 中调用。(函数在page_load中循环无穷大的时间(。
但是有什么方法可以使用 angular2 属性在 HTML 本身中做吗?
假设您使用的是AngulaJS,请检查对象键以确定从对象中是否存在test
开始的属性。
<label ng-if="checkValue()" for="lblConcat">My label
$scope.checkValue = function(){
var status = false
if(Object.keys($scope.model).some((k) => ~k.indexOf("test") && !k )){
status = true
}
return status
}