Reputation: 609
<input name="name" type="text" ng-model="numbers" mandatory>
How to remove and add class of mandatory dinamically in Angular JS?
Note : "mandatory" is custom class which is implemented by me.
Thanks.
Upvotes: 1
Views: 595
Reputation: 1365
Assuming you want to change the class on button click
<input name="name" type="text" ng-model="numbers" mandatory ng-class="class">
<button ng-click="changeClass()">Change Class</button>
Now Add or remove class in controller
app.controller("con",function($scope){
$scope.class = "class1";
$scope.changeClass = function(){
if ($scope.class === "class1")
$scope.class = "class2";
else
$scope.class = "class1";
};
});
Upvotes: 0
Reputation: 3944
ng-class is option in Angularjs to add class dynamically
follow the doc for more info
https://docs.angularjs.org/api/ng/directive/ngClass
Upvotes: 0
Reputation: 8488
I don't understand what you mean by mandatory. But to apply class based on condition we do
<input name="name" type="text" ng-model="numbers" mandatory ng-class="{className: expression}">
Upvotes: 1