在您的 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,那么所有元素都会被创建,否则元素不会被创建。