我正在尝试通过 AngularJS 控制 CSS。我为此目的使用 ng-class 和 ng-click .....为此我制作了两个函数 showError 和 showWarning。我试图通过分别设置它们的属性 true 和 false 来更改 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 属性////