问题
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