Hello,
I'm beginner of Angularjs. Normally by jquery, to bind an event for the HTML element, I do like this:
$( "#foo" ).bind( "click", function() {
alert( "User clicked on 'foo.'" );
});
I'm using Angular in my project, so how to bind the event to the element like jquery in angular ?
Anyone can help me
Thank you
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.
Wouldn't you do that in the directive?
I'm new to angular as well. I suppose you are trying to bridge what you know in order to learn something new.
My approach has been to dump what I know and learn the idioms of angular first. Ymmv.
So I would put ng-click on the button until I understood what angular has to offer.
I would use scm to merge my changes with the html dev if they can't/won't so angular.
Fwiw, I would never have a class named classButton.
You don't need a directive for a button. You just need an html button and add the angular attribute...or am I misunderstanding something fundamental about your problem?
On a single view? Then probably a directive, but I'll defer to someone with more angular experience.
<div id="foo> </div>
<script>
$( "#foo" ).bind( "click", function() {
alert( "User clicked on 'foo.'" );
});
</script>
<div id="cntr" ng-controller="fooController as myCtrl"><div id="foo" ng-click="myCtrl.selectFoo()" > </div></div>