ng-if :隐藏/显示属性.怎么做

ng-if : hide/show attribute. How to do it?

本文关键字:属性 显示 隐藏 ng-if      更新时间:2023-09-26

我需要这样的东西:

$scope.toggle = true;
<a If(toggle){ ng-click="vm.addFilter()" } else{ '' } >Add Policy</a>

我可以尽可能简单地做到这一点吗?

你想这样做吗?

//If you want to hide the element use this
<a ng-if="toggle" ng-click="vm.addFilter()" >Add Policy</a>

或者这个

//If you want to avoid the event with toggle variable
<a ng-click="toggle && vm.addFilter()" >Add Policy</a>

你不能使用角度核心指令添加或删除任何属性,你可以做如下的事情。我想你不想有条件地打电话给vm.addFilter()

<a ng-click="toggle && vm.addFilter()">Add Policy</a>

&&如何深入工作?

@deceze有一个很好的观点,除非它正在执行某些操作,否则不需要显示元素。因此,您也可以按照他的回答中@Serginho的建议使用ng-if隐藏/删除元素。