In jQuery:
 

<div id="foo> </div>

 

<script> 

$( "#foo" ).bind( "click", *function*() {  

alert( "User clicked on 'foo.'" );

});

</script> 


In Angular:

<div id="cntr" ng-controller="fooController as myCtrl">
    <div id="foo" ng-click="myCtrl.selectFoo()" > </div> 
</div>


where the FooController manages all interactions. 

   - ng-controller is an AngularJS Directive that defines the scope of 
   FooController to the DIV "cntr" and all its content
   - ng-Click is an AngularJS `attribute` directive that knows how to bind 
   a `click` event listener to the `foo` DOM element and then proxies the 
   click handler to invoke the expression: myCtrl.selectFoo().

This approach 

   - Separates firewalls DOM UI from business logic in Controllers, 
   Services, and Models
   - Uses Directives to modify or enhance DOM elements using databinding as 
   sources to update the DOM and evaluated expressions to update the business 
   layers.
   

As you can see, AngularJS is a very different perspective [from jQuery] on 
how to interact with the DOM elements. 

Hope this helps provide some clarity.


On Thursday, January 9, 2014 6:00:58 PM UTC-6, biloki wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to