I'm wanting to show/hide a div based on whether a variable is null or not.
<div ng-show="myvar"></div>
Note: the variable in my case is an object.
A very simple question, but I can't seem to make it work.
Thanks.
$("#bar"). find('div. section:empty'). hide();
You can simply use typeof. It will check undefined, null, 0 and "" also.
The hidden attribute hides the <div> element. You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <div> element is not visible, but it maintains its position on the page.
<div ng-hide="myvar == null"></div>
or
<div ng-show="myvar != null"></div>
To clarify, the above example does work, my code in the example did not work for unrelated reasons.
If myvar is false, null or has never been used before (i.e. $scope.myvar or $rootScope.myvar never called), the div will not show. Once any value has been assigned to it, the div will show, except if the value is specifically false.
The following will cause the div to show:
$scope.myvar = "Hello World";
or
$scope.myvar = true;
The following will hide the div:
$scope.myvar = null;
or
$scope.myvar = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With