1

I was using jquery ealier before starting to use angularjs.

Earlier I head this:-

$('[data-action^="backtop"]').click(function(){

});

and now after integrating angular this does not work on click.

Is there a way i can correct without having to change everything to directives.

1
  • Found a solution, using jQuery's event delegation. So i will be doing $(document).on('click','[data-action=^="backdrop"]',function(){}) Commented Jan 2, 2016 at 19:34

1 Answer 1

0

Where you'd put a data-action and then a selector over it that fires a handler - use a ng-click.

In the template:

<div ng-controller="MyCtrl as ctrl"> <!-- or whatever container --> 
 <button ng-click="ctrl.backtop()" ng-init="count=0">
</div>

And in the controller:

class MyCtrl {
    backtop() {
       // code here, what you had in the click handler
    }
}
app.controller("MyCtrl", MyCtrl);

Or in ES5 syntax:

app.controller("MyCtrl", function(){ 
    this.backtop = function() { /* handler code here */ }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Nice Solution, but i cannot actually do that as i will have to migrate too many things to make them work again. I have loads of such selectors.
I want to use angular now as i have much more implementations to do and i will be migrating to angular soon, but for the time being i just needed a quick solution.
Then you might as well not use Angular, you can't use selectors as the event handlers won't be aware of Angular's change tracking - you'll have lots of confusing bugs - it won't be worth it

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.