以下代码段不起作用请建议任何其他方式
<html>
`<div id="tablediv" ng-model="ngtable">
<div ng-show="ngtable">
<div ng-if="currentdevicetype == 'condition1'">
<!-- Other code to display contents -->
</div>`
</div>
</div>
</html>
以下代码段不起作用请建议任何其他方式
<html>
`<div id="tablediv" ng-model="ngtable">
<div ng-show="ngtable">
<div ng-if="currentdevicetype == 'condition1'">
<!-- Other code to display contents -->
</div>`
</div>
</div>
</html>
在您的 html 代码中,您使用了错误的东西,因为您使用ng-model
的是 div 。
<html>
<div id="tablediv" ng-model="ngtable">
<div ng-show="ngtable">
<div ng-if="currentdevicetype == 'condition1'">
<!-- Other code to display contents -->
</div>
</div>
</div>
</html>
ng-model 用于绑定任何 inputbox/textarea/select 之类的标签的值,您不能像这样绑定任何值:
<div id="tablediv" ng-model="ngtable">
如果您删除它,ng-model
那么您的代码将是这样的:
<html>
<div id="tablediv">
<div ng-show="ngtable">
<div ng-if="currentdevicetype == 'condition1'">
<!-- Other code to display contents -->
</div>
</div>
</div>
</html>
现在,如果ngtable
有一些价值,那就ng-show=true
意味着
<div ng-show=true>
// all the elements are visible on the DOM.
</div>
但是,如果如果ngtable
没有任何值,则意味着ng-show=false
:
<div ng-show=false>
// all the elements are not visible on the DOM.
</div>
在这段代码中:
<div ng-if="currentdevicetype == 'condition1'">
<!-- Other code to display contents -->
</div>
如果ng-if="currentdevicetype == 'condition1'"
返回 true 则将创建所有元素,否则将不会创建元素。
查看此问题以了解 ng-show 和 ng-if 之间的区别以及在哪里以及如何使用它们:
是的,你可以,两者是不同的。
ng-show
当表达式计算结果为时设置元素的,而display:none
当表达式计算结果为时从 DOM 中删除元素false
ng-if
false