我想通過AngularJS控制CSS。我正在使用ng-class和ng-click來達到這個目的.....我爲此做了兩個函數showError和showWarning。我試圖通過分別使用AngularJS控制CSS
設置其屬性真假改變CSS -------- --------- CSS
.error {
background-color: red;
}
.warning {
background-color: orange;
}
------- HTML ---------
<div>
<h2> {{ message }} </h2>
<ul>
<li class="menu-disabled-{{ isDisabled }}" ng-click="stun()"> Stun</li>
</ul>
<div class='{ warning : {{ isWarning }}, error : {{ isError }} }'>
{{ messageText }}</div>
<button ng-click="showError()"> Simulate Error</button>
<button ng-click="showWarning()">Simulate Warning</button>
</div>
------- JS -----------
$scope.isError = false;
$scope.isWaring = false;
$scope.showError = function(){
console.log("error here");
$scope.messageText = "This is an error";
$scope.isError = true;
$scope.isWaring = false;
}//showError
$scope.showWarning = function() {
console.log("warning here");
$scope.messageText = "Just a Warning, Carry ON !!!";
$scope.isError = false;
$scope.isWaring = true;
}//showWarning
我成功訪問功能並使用ng-click打印messageText但不能改變的CSS屬性////
Sir TextText是一個靜態內容....我想用bg-color生成一個動態內容??? ......... plz help –