例子:
.error{background-color:red;} .warning{background-color:yellow;}
<div ng-controller='HeaderController'>
<div ng-class='{error:isError,warning:isWarning}'>{{messageText}}</div>
<button ng-click='showError()'>展示error</button>
<button ng-click='showWarning()'>展示warning</button>
</div> function HeaderController($scope){
$scope.isError= false;
$scope.isWarning = false; $scope.showError= function(){
$scope.messageText= 'this is an error!';
$scope.isError=true;
$scope.isWarning=false;
};
$scope.showWarning = function(){
$scope.messageText= 'this is an warning!';
$scope.isError=false;
$scope.isWarning=true;
};
}