Skip to content

Instantly share code, notes, and snippets.

@niklas-r
Created May 16, 2014 07:45
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 niklas-r/cf82c259f8305bc3770c to your computer and use it in GitHub Desktop.
Save niklas-r/cf82c259f8305bc3770c to your computer and use it in GitHub Desktop.
AngularJS stop event directive. Used to stopPropagation in AngularJS. Thanks to http://stackoverflow.com/a/14547223
<!doctype html>
<html lang="en" ng-app>
<head>
<meta charset="UTF-8">
<title>Stop Events</title>
</head>
<body ng-controller="appCtrl">
<div ng-click="doSomething()">
<p>Hey!</p>
<div ng-click="doSomethingElse()" stop-event="click">
<p>Ho!</p>
</div>
</div>
</body>
</html>
angular.module('stopEvents', [])
.directive('stopEvent', function () {
return {
restrict: 'A',
link: function (scope, element, attr) {
element.bind(attr.stopEvent, function (e) {
e.stopPropagation();
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment