Let's say in the condition of AngularJS's ngShow
, what if a property doesn't exist?
For example, if vm.foo
is 1
, then what if in the HTML, there is a
<div ng-show="myCtrl.foo.bar.wa.la">
hello
</div>
and what if it is
<div ng-show="!myCtrl.foo.bar.wa.la">
hello
</div>
Example at: https://jsfiddle.net/4yg2ocy6/1/
(If it is pure JavaScript, it will raise an exception)
I suspect that
myCtrl.foo.bar.wa.la
is treated by AngularJS as the same as:
(myCtrl.foo && myCtrl.foo.bar && myCtrl.foo.bar.wa && myCtrl.foo.bar.wa.la)
and
!myCtrl.foo.bar.wa.la
is the same as
!(myCtrl.foo && myCtrl.foo.bar && myCtrl.foo.bar.wa && myCtrl.foo.bar.wa.la)
but I can't find any documentation about it.
Another possibility is that it treats (myCtrl.foo.bar.wa.la)
as one unit, if Angular can evaluate it, then return the result, but if it raises an exception, catch it and return false. So for !myCtrl.foo.bar.wa.la
, it will treat it as !false
and therefore is true
.
Is there a more definite spec for this?