Skip to content

Instantly share code, notes, and snippets.

@paulwsmith
Last active August 29, 2015 14:01
Show Gist options
  • Save paulwsmith/6c09ccbae1b257a38f7b to your computer and use it in GitHub Desktop.
Save paulwsmith/6c09ccbae1b257a38f7b to your computer and use it in GitHub Desktop.
Plugin API - Events
wizehive.controller('DataCntl', ['$scope', 'PluginCommunication', function($scope, PluginCommunication) {
// Send record data
$scope.$watch('record', function(record) {
PluginCommunication.$broadcast('data-cntl-record', record);
});
// Get record data from plugin
PluginCommunication.$on('DataCntl.record-update', function(evt, record) {
$scope.record = record;
});
}]);
wizehive.service('PluginCommunication', ['$rootScope', function($rootScope) {
this.scope = $rootScope.$new(true); // isolate scope
this.eventScope = {
$on: this.scope.$on,
$broadcast: this.scope.$broadcast,
$emit: this.scope.$emit
};
return this.eventScope;
}]);
wizehive.controller('AwesomePluginCntl', ['$scope', 'PluginCommunication', function($scope), PluginCommunication {
// Get record data from app
PluginCommunication.$on('data-cntl-record', function(evt, record) {
$scope.record = record;
});
// Send record data up
PluginCommunication.$emit('data-cntl-record-update', $scope.record);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment