1

I'm trying to figure out the best way to add a function to the existing ng-click function below that will add a class to the element upon execution.

 $ctrl.next = function(id) {
    $state.go('individual', {id : id}, {reload : true});
     ga.track({
        action:'Button click',
        label:'Navigation Button Right',
        category:'Button'
    });

  }

Basically this function triggers a state change to the next item in an array that comes from a database and tracks the element clicked.

1 Answer 1

1

Without a sample, I am not 100% clear on what you have. This plunker demo shows clicking a button, and changing it's class to make it blue.

JS

app.controller('ctrl',function($scope){
  $scope.clickFunction = function(evt) {
   angular.element(evt.srcElement).addClass('clicked-button');
  }
});

HTML

  <div ng-controller='ctrl'>
    <button ng-click="clickFunction($event)">Click Me</button>
  </div>
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, So I have a ng-click setup in my routes that triggers a function to track the button. With my controller as $ctrl I basically wanted to try and be smart and work out away to have another function run inside my $ctrl.next() so that it just adds ".class" to the element i have ng-click="ctrl.next()" on

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.