Agzam Agzam - 6 months ago 28
AngularJS Question

ngHide or ngShow based on number of children

I know it is absolutely stupid thing to ask but I'm curious
is there a way do something like:

<div ng-show='this.children.length > 0'> // shown
<div>

</div>
</div>

Answer

To add to @Josh David Miller answer, the following values are considered falsy in angular.

1)An Empty Array

2)An Empty String //Even a space is considered true

3)An Boolean with false

4)undefined

5)null

6) 0

So, David's answer can be written as,

<div ng-show="items.length">
  <div ng-repeat="item in items">
    <!-- ... -->
  </div>
</div>

or even shorter,

<div ng-show="items">
  <div ng-repeat="item in items">
    <!-- ... -->
  </div>
</div>