Skip to content

Instantly share code, notes, and snippets.

REWOO Technologies AG rewoo

Block or report user

Report or block rewoo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@rewoo
rewoo / my-awesome-directive.js
Last active Jan 3, 2018
Automatic unbind pattern for event bindings in directives using AngularJS
View my-awesome-directive.js
angular.module('app', [])
.directive('myAwsomeDirective', function($rootScope) {
return {
restrict: 'A',
link: function(scope) {
// $scope.$on() returns an unbind function of the binding
//
// So use the bind function directly within scope's $destroy event
// to unbind event automatically.
scope.$on('$destroy', $rootScope.$on('my:event', function() {
You can’t perform that action at this time.