ng-show not working with UnderscoreJS's _.isNull but works with val === null

不想你离开。 提交于 2019-12-11 11:15:45

问题


I've got an element with an ng-show directive and when I use the UnderscoreJS helper function _.isNull it work the same was as using the standard === operator.

So this displays the content with newJobWorkPercentage is null.

<div class="form-group" ng-show="newJobWorkPercentage === null">
 ... some content
</div>

but this doesn't

<div class="form-group" ng-show="_.isNull(newJobWorkPercentage)">
 ... some content
</div>

I can just use the === in my app, I'm just intrigued why the helper doesn't work.


回答1:


Angular expressions are only evaluated against the $scope of that view. So to use underscore in your view you would need to add it to the $scope variable inside your controller:

$scope._ = _;

Now you will be able to use the underscore functions inside expressions.



来源:https://stackoverflow.com/questions/22563549/ng-show-not-working-with-underscorejss-isnull-but-works-with-val-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!