0
如果我設置了$scope.true = false;
,我期望引用true
的Angular表達式評估爲false。同樣,我期望和$scope.undefined = true
產生類似的結果。
殘暴的命名,爲什麼不這些工作?在角碼中的哪個位置確定$scope
屬性是否會被引用?
var myApp = angular.module('myapp', []);
myApp.controller('myctrl', function($scope) {
$scope.foo = "bar";
$scope.true = false;
$scope.true2 = false;
$scope.false = true;
$scope.false2 = true;
$scope.undefined = true;
$scope.undefined2 = true;
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp" ng-controller="myctrl">
<p>{{ foo }}</p>
<div ng-show="true">
$scope.true is equal to false here. ng-show should hide this.
</div>
<div ng-show="true2">
$scope.true2 is equal to false here. ng-show hides this.
</div>
<div ng-hide="false">
$scope.false is equal to true here. ng-hide should hide this.
</div>
<div ng-hide="false2">
$scope.false2 is equal to true here. ng-hide hides this.
</div>
<div ng-hide="undefined">
$scope.undefined is equal to true here. ng-hide should hide this.
</div>
<div ng-hide="undefined2">
$scope.undefined2 is equal to true here. ng-hide hides this.
</div>
</div>
我永遠不會編碼這個,但想知道發生了什麼。你的解釋正是我正在尋找的。謝謝! – adamdport