Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngHide or ngShow based on number of children

Tags:

angularjs

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> 
like image 528
iLemming Avatar asked Apr 09 '13 21:04

iLemming


1 Answers

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> 
like image 171
Rajkamal Subramanian Avatar answered Sep 20 '22 12:09

Rajkamal Subramanian