改变CSS Angularjs

改变CSS Angularjs

问题描述:

我想基于NG-模型改变CSS Angularjs

的index.html

<button ng-click="changeType()">Change</button> 
<label class="fee-type" ng-style="feeType ==='one' && {'class':'disabled-class'}" for="fixed2">Client Contengency Fee</label> 
<label class="fee-type" ng-style="feeType ==='one' && {'class':'disabled-class'}" for="fixed1">Fixed Fee Per Property</label> 

默认类是费用型但是当更改标签的颜色和游标类型然后按钮被点击其类应改为禁用类

index.css

.fee-type { 
    float: left; 
    clear: none; 
    display: block; 
    padding: 2px 1em 0 0; 
    color: black; 
} 

.disabled-class { 
    color:gray; 
    cursor: not-allowed; 
} 

index.js

$scope.feeType= two; 

$scope.changeType= function(){ 
    $scope.feeType=one; 
} 
+0

使用纳克级,而不是 – Vanojx1

您应该使用ng-class代替ng-styleng-class添加条件,应用CSS类标签。

HTML:

<button ng-click="changeType()">Change</button> 
<label class="fee-type" ng-class="{'disabled-class':feeType ==='one'}" for="fixed2">Client Contengency Fee</label> 
<label class="fee-type" ng-class="{'disabled-class':feeType ==='two'}" for="fixed1">Fixed Fee Per Property</label> 

和控制器

$scope.feeType = 'two'; 

$scope.changeType = function() { 
    $scope.feeType = 'one'; 
}; 
+0

其工作:P谢谢你的'feeType'帮助 –

+0

值应该是'string'所以用引号像在你的控制器中“one”而不是“one” –