Angular ng-if not true

AngularjsAngular Ng-If

Angularjs Problem Overview


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.

Angularjs Solutions


Solution 1 - Angularjs

use this

> ng-if="area == false"

OR

> ng-if="area == true"

this may help someone

Solution 2 - Angularjs

Use like this

<div ng-if="data.IsActive === 1">InActive</div>
<div ng-if="data.IsActive === 0">Active</div>

Solution 3 - Angularjs

Just use for True:

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

and for False:

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

Solution 4 - Angularjs

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

Solution 5 - Angularjs

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>

Solution 6 - Angularjs

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3289197View Question on Stackoverflow
Solution 1 - AngularjsSachin Sudhakar SonawaneView Answer on Stackoverflow
Solution 2 - AngularjsRajView Answer on Stackoverflow
Solution 3 - Angularjscoloma1984View Answer on Stackoverflow
Solution 4 - AngularjsRizwanView Answer on Stackoverflow
Solution 5 - AngularjsaslantorretView Answer on Stackoverflow
Solution 6 - AngularjsM Usman NadeemView Answer on Stackoverflow