ng-class css样式

<style>
.error{background-color: red;}
.warning{background-color: yellow;}
</style>

<script>

  

app.controller("headerController",function($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="just a warning";
$scope.isError=false;
$scope.isWarning=true;
}
});

<script>

 

<body>

<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>
</body>

 

 

posted @ 2014-04-26 21:47  粉条  Views(1469)  Comments(0)    收藏  举报