Skip to content

Instantly share code, notes, and snippets.

@BioPhoton
Last active August 29, 2015 14:24
Show Gist options
  • Save BioPhoton/d6c76e31a5ae215254cb to your computer and use it in GitHub Desktop.
Save BioPhoton/d6c76e31a5ae215254cb to your computer and use it in GitHub Desktop.
AngularJS Event-Channel (slides (here) [http://slides.com/michael_hladky/event-channel#/] )
.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