0

我想根据 ng-model 更改标签颜色和光标类型

索引.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>

默认类是费用类型,但是当单击按钮时,其类应更改为禁用类

索引.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;
}
4

1 回答 1

2

您应该使用ng-class代替ng-style并添加条件ng-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';
};
于 2017-08-16T12:44:53.513 回答