Skip to content

Instantly share code, notes, and snippets.

@srfrnk
Created June 27, 2014 07:39
Show Gist options
  • Save srfrnk/7397da5d001d2316a2d0 to your computer and use it in GitHub Desktop.
Save srfrnk/7397da5d001d2316a2d0 to your computer and use it in GitHub Desktop.
NG directive to disable click event from bubbling up...
define("directives/captureClick", ["app"], function (app) {
return app.directive('captureClick', [function () {
return {
restrict: "A",
controller: ["$scope", "$element", "$attrs", "$transclude", function ($scope, $element, $attrs, $transclude) {
$element.click(function (e) {
e.stopPropagation();
});
}]
};
}]);
});
@srfrnk
Copy link
Author

srfrnk commented Jun 27, 2014

Use when you have an inner element nested within a larger container and you need to have ng-click handled differently for the inner and outer elements. (to prevent every click on the inner child bubbling and also triggering the parent!)

Usage:
<.... capture-click ></...>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment