Reputation: 797
I have 3 buttons and I want change its style when the button was clicked. I don't know if angular has its own function like ng-class, ng-click or similar, but I not get it to works.
<button class="btn1" ng-click="function1"></button>
<button class="btn2" ng-click="function2"></button>
<button class="btn3" ng-click="function3"></button>
is possible call to another css class from js(in the function)? Thanks.
Upvotes: 0
Views: 2264
Reputation: 2181
Inside your function definition you could set some variable on the scope, which you could then use inside an ng-class
directive.
Example
Somewhere in your controller:
$scope.function1 = function () {
$scope.clickedButton1 = true;
}
In your template:
<button
class="btn1"
ng-class="{'button1Clicked': clickedButton1}"
ng-click="function1()">Button1</button>
Upvotes: 0
Reputation: 1171
You can add a class dynamically on ng-click.
<li ng-class="{'xyzclass':addClass}" ng-click="addClass = TRUE"><a href="#users" >Users</a></li>
Upvotes: 1
Reputation: 21005
Try this for starters
<button
class="btn_theme btn1"
ng-class="{'clicked':clicker}"
type="submit" ng-click="select1()">Hello</button>
with this in the controller
$scope.select1 = function() {
$scope.clicker = !$scope.clicker
}
See http://plnkr.co/edit/zKsYoD3coPlZRHQkRQO1?p=preview
Upvotes: 2