是否angularjs treates null作为$ scope.null?treates、angularjs、scope、null

2023-09-13 04:45:44 作者:深爱的另一个名字叫卑微

举例问题

<div ng-show="bar !== null">hello</div>

这是在范围评为

$scope.bar !== null

或者是因为这?

$scope.bar !== $scope.null

请注意,在最后一种情况下,$ scope.null将是不确定的和例子似乎工作的权利。

Note that in last case, $scope.null would be undefined and the example would seem to work right.

奖励:

如果巴= null,则发生这种情况。

if bar = null then this happens

// this does not work (shows hello)
<div ng-show="bar !== null">hello</div>

不给相同的结果

// this works ok (does not show hello)
<div ng-show="bar != null">hello</div>

为什么会发生呢?

why does that happen?

推荐答案

没有,角识别在EX pressions一些JS原语和就是其中之一。

No, Angular recognizes some JS primitives in expressions, and null is among them.