如何显示/隐藏,如果变量为空 [英] How to show/hide if variable is null
问题描述
我想显示/隐藏基于一个变量是否为空或不是一个div。
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.
感谢。
推荐答案
要澄清一下,上面的例子不工作,在我的例子code没有为不相干的原因工作。
To clarify, the above example does work, my code in the example did not work for unrelated reasons.
如果myvar的是假的,空或之前(即$ scope.myvar或$ rootScope.myvar永远不会被调用)从未使用过,在div将不显示。一旦任何值已被分配给它,在div将显示,除非该值具体假
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.
以下原因会导致股利显示:
$scope.myvar = "Hello World";
或
$scope.myvar = true;
下面将隐藏的div:
$scope.myvar = null;
或
$scope.myvar = false;
这篇关于如何显示/隐藏,如果变量为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!