Last active
August 29, 2015 14:24
-
-
Save BioPhoton/d6c76e31a5ae215254cb to your computer and use it in GitHub Desktop.
AngularJS Event-Channel (slides (here) [http://slides.com/michael_hladky/event-channel#/] )
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
.config('myEvents', function() { | |
valueChanged : 'valueChanged' | |
}); | |
.service('myChannel', function($rootScope, myEvents) { | |
var publishValueChanged = function (newVlaue) { | |
var args = {value: newVlaue}; | |
$rootScope.$emit(myEvents.valueChanged, args); | |
}; | |
var onValueChanged = function($scope, handler) { | |
var unsubToValueChanged = $rootScope.$on(myEvents.valueChanged, function(event, args) { | |
handler(args.value); | |
}); | |
$scope.$on('$destroy', function() { | |
unsubToValueChanged(); | |
}); | |
}; | |
return { | |
publishValueChanged : publishValueChanged, | |
onValueChanged : onValueChanged | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment