angularjs 是否将 null 视为 $scope.null? [英] Does angularjs treates null as $scope.null?
本文介绍了angularjs 是否将 null 视为 $scope.null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题示例
<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.
奖励:
如果 bar = 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>
为什么会这样?
推荐答案
不,Angular 识别表达式中的一些JS原语,null
就是其中之一.
No, Angular recognizes some JS primitives in expressions, and null
is among them.
这篇关于angularjs 是否将 null 视为 $scope.null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文