Angularjs快速入门(四)-css类和样式

例子:

1 .error{background-color:red;}
2 
3 .warning{background-color:yellow;}
View Code
 1 <div ng-controller='HeaderController'>
 2     <div ng-class='{error:isError,warning:isWarning}'>{{messageText}}</div>
 3     <button ng-click='showError()'>展示error</button>
 4      <button ng-click='showWarning()'>展示warning</button>
 5 </div>
 6 
 7 function HeaderController($scope){
 8   $scope.isError= false;
 9   $scope.isWarning = false;
10 
11   $scope.showError= function(){
12     $scope.messageText= 'this is an error!';
13     $scope.isError=true;
14     $scope.isWarning=false;    
15 };      
16    $scope.showWarning = function(){
17      $scope.messageText= 'this is an warning!';
18     $scope.isError=false;
19     $scope.isWarning=true;    
20 }; 
21 }
原文地址:https://www.cnblogs.com/937522zy/p/5007052.html