I have the following. If i do a console.log($scope.variable), i get 2 values of it at different times on the console.
It shows undefined and '' at the console.
I want to hide a div on basis of this value. I do the following
<div ng-hide="$scope.variable== undefined || $scope.variable = ''>
Hide this section
</div>
It should be able to hide the section since the values are either undefined and '' at all cases. However the div still shows at the UI. Am i missing any constraint or not putting the condition check properly ?
I have the following. If i do a console.log($scope.variable), i get 2 values of it at different times on the console.
It shows undefined and '' at the console.
I want to hide a div on basis of this value. I do the following
<div ng-hide="$scope.variable== undefined || $scope.variable = ''>
Hide this section
</div>
It should be able to hide the section since the values are either undefined and '' at all cases. However the div still shows at the UI. Am i missing any constraint or not putting the condition check properly ?
Share Improve this question asked Mar 30, 2017 at 18:57 RihanaRihana 4432 gold badges7 silver badges14 bronze badges2 Answers
Reset to default 4<div ng-show="variable != null"></div>
or
<div ng-hide="variable == null>
Hide this section
</div>
You could use ng-if in this case, which would result in better performance,
<div ng-if="variable == null">
Hide this section
</div>
Ng-show
should never be used.It will load view in value and just hides it by setting css
property display:none
. Instead use ng-if
<div ng-if="variable != null"></div>
or
<div ng-if="variable === null>
Hide this section
</div>