1

Following code snippet does not work Please suggest any other way of doing it

<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> 
sanikak14
  • 11
  • 3

3 Answers3

0

Yes you can, Both are different.

ng-show

sets the display:none of the element when expression evaluates to false while ng-if removes the element from the DOM when the expression evaluates to false

Shubhranshu
  • 511
  • 3
  • 12
0

Check out this question to know the differences between ng-show and ng-if & where and How to use them:

When to favor ng-if vs. ng-show/ng-hide?

Community
  • 1
  • 1
The JD
  • 13
  • 12
0

In your html code , you are using something wrong, because you are using ng-model for a 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 is used to bind the value of any inputbox/textarea/select like tags, you can not bind any value like this:

<div id="tablediv" ng-model="ngtable">

if you remove this ng-model then your code would be like this:

        <html>
            <div id="tablediv">
            <div ng-show="ngtable">
            <div ng-if="currentdevicetype == 'condition1'">
            <!-- Other code to display contents -->
            </div>
            </div>
            </div>
       </html>

Now, if ngtable have some value it means ng-show=true then

 <div ng-show=true>
            // all the elements are visible on the DOM.
 </div>

but , if if ngtable do not have any value it means ng-show=false then :

<div ng-show=false>
                // all the elements are not visible on the DOM.
     </div>

And inside this code:

<div ng-if="currentdevicetype == 'condition1'">
        <!-- Other code to display contents -->
</div>

if ng-if="currentdevicetype == 'condition1'" returns true then all the elements would be create, otherwise element will not be created.

Shubham Verma
  • 8,783
  • 6
  • 58
  • 79