66

Why doesn't this work.

<li ng-if="!area"></li>

Feels a bit illogical since

<li ng-if="area"></li>

works just fine.

'area' is defined in scope as true/false Any workarounds for this? I would prefer not to use ng-show/ng-hide since both of them renders items in DOM.

user3289197
  • 821
  • 2
  • 7
  • 6

6 Answers6

83

use this

ng-if="area == false"

OR

ng-if="area == true"

this may help someone

7

Use like this

<div ng-if="data.IsActive === 1">InActive</div>
<div ng-if="data.IsActive === 0">Active</div>
Raj
  • 409
  • 7
  • 23
3

try this:

<div ng-if="$scope.length == 0" ? true : false></div>

and show or hide

<div ng-show="$scope.length == 0"></div>

else it will be hide

-----------------or--------------------------

if you are using $ctrl than code will be like this:

try this:

<div ng-if="$ctrl.length == 0" ? true : false></div>

and show or hide

<div ng-show="$ctrl.length == 0"></div>

else it will be hide

Rizo
  • 2,391
  • 1
  • 15
  • 18
2

Just use for True:

<li ng-if="area"></li>

and for False:

<li ng-if="area === false"></li>
coloma1984
  • 41
  • 4
0

In angular 1, you can use ng-show and ng-hide.In your case, you would use ng-hide. For example:

<li ng-hide="area"></li>
aslantorret
  • 235
  • 3
  • 10
  • The side-effect to this approach is that `ng-hide` will keep the elements in the dom, while `ng-if` does not render them at all. – serialworm May 31 '18 at 00:02
0

you are not using the $scope you must use $ctrl.area or $scope.area instead of area

M Usman Nadeem
  • 383
  • 1
  • 13