角JS方法不工作我有以下代碼:AngularJS:條件語句在控制器
<!DOCTYPE html>
<html data-ng-app>
<head>
<title></title>
<style>
.menu-disabled-true {
color: gray;
}
.menu-disabled-false {
color: red;
}
.menu-disabled-green {
color: green;
}
</style>
</head>
<body >
<script src="angular.min.js"></script>
<script>
function DeathrayMenuController($scope) {
$scope.isDisabled = false;
$scope.stun = function() {
// stun the target, then disable menu to allow regeneration
if($scope.isDisabled == 'false'){
$scope.isDisabled = 'true';
}else if($scope.isDisabled == 'true'){
$scope.isDisabled = 'green';
}
};
}
</script>
<div ng-controller='DeathrayMenuController'>
<ul>
<li class='menu-disabled-{{isDisabled}}' ng-click='stun()'>Stun</li>
</ul>
</div></body>
</html>
現在,每當我在眩暈單擊<li>
然後我希望它改變顏色按照方法內控制器。
有人能幫我理解爲什麼它不起作用嗎?
我準備了一個小提琴http://jsfiddle.net/alexeime/mddDV/ – Alexei
@CodingNinja你是絕對正確的..但仍然在糾正它,我得到一個單一的過渡紅色變成灰色。但在重新點擊我沒有得到綠色 – Padyster
@Padyster第一次點擊:'false => true',第二次點擊:'true => green',第三次點擊:'既不虛假也不真實,所以沒有條件符合 – Yoshi