Last active
August 29, 2015 14:01
-
-
Save paulwsmith/6c09ccbae1b257a38f7b to your computer and use it in GitHub Desktop.
Plugin API - Events
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
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; | |
}); | |
}]); |
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
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; | |
}]); |
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
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