Skip to content

Instantly share code, notes, and snippets.

@koganei
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koganei/1aad26a2a180abefa303 to your computer and use it in GitHub Desktop.
Save koganei/1aad26a2a180abefa303 to your computer and use it in GitHub Desktop.
Event delegation in AngularJS
var app=angular.module('myApp', []);
app.directive('exampleDirective1', function() {
return {
restrict: 'E',
template: '<span>Click me! [{{clickCount}}]</span>',
replace: true,
link: function(scope, elm, attrs) {
scope.clickCount = 0;
elm.bind('click', 'span', function() {
scope.$apply(function() {
scope.clickCount++;
});
});
}
};
});
<div>
<example-directive1></example-directive1>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment