0

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.

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

If you set up a plnkr, I can help connect everything up
1

You can add a class dynamically on ng-click.

<li ng-class="{'xyzclass':addClass}" ng-click="addClass = TRUE"><a href="#users" >Users</a></li>

1 Comment

how? I need use a function, is possible function+add css in the same call?
0

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>

Comments

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.