Created
May 16, 2014 07:45
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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