0

I want to change label color and cursor type based on ng-model

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>

The default class is fee-type but when then button get clicked its class should change to disabled-class

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;
}
1
  • use ng-class instead Commented Aug 16, 2017 at 12:42

1 Answer 1

2

You should use ng-class instead of ng-style and add condition in ng-class to apply css class in your label.

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>

and controller

$scope.feeType = 'two';

$scope.changeType = function() {
   $scope.feeType = 'one';
};
Sign up to request clarification or add additional context in comments.

1 Comment

value of feeType should be string so use quotation like 'one' instead of one in your controller

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.