1

I'm little confused with onclick function , with angularjs...

in my controller, i put this :

$('#mapReload').click(function () {
    alert('lol');
});

nothing work... jquery is correctly added, where i'm wrong ?

3
  • 3
    Why do you need jQuery event binding? Whats wrong with ngClick? Commented Apr 8, 2014 at 12:56
  • Are you even using angular? Can you update with your controller and template code? Commented Apr 8, 2014 at 12:59
  • try "$window.alert('lol');" Commented Apr 8, 2014 at 13:00

1 Answer 1

1

In your HTML use ng-click for button click:

<button ng-click="reloadMap()">Map Reload</button>

And in your angularJS controller, write click handler:

$scope.reloadMap = function() {
    alert('lol');
};
Sign up to request clarification or add additional context in comments.

4 Comments

There are two problems with your jsfiddle: 1). ng-controller directive should be given to parent container element. Yours is incorrect. 2). ng-app directive is needed for angular app to work, which i have added in working jsFiddle in fiddle options=>body tag.
why angularjs is needed in <head> ? i learn to put my JS in last, in <body>
It is only for jsFiddle to work properly. In your server, you can add your angularjs code file at the end of the page and this code will work. You can test jsFiddle with No wrap - in <body> and it will place js code just before </body> and that also will work.
I hope this helped you. Let us know. Thanks.

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.