$scope.true = false;
と設定すると、true
を参照するAngular式はfalseと評価されます。同様に、$scope.false = true
と$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