1

以下代码段不起作用请建议任何其他方式

<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> 
4

3 回答 3

0

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

于 2017-01-24T06:51:25.327 回答
0

查看此问题以了解 ng-show 和 ng-if 之间的区别以及在哪里以及如何使用它们:

何时支持 ng-if 与 ng-show/ng-hide?

于 2017-01-24T06:19:01.630 回答
0

是的,你可以,两者是不同的。

ng-show

当表达式计算结果为时设置元素的,而display:none当表达式计算结果为时从 DOM 中删除元素falseng-iffalse

于 2017-01-24T06:15:08.113 回答