Skip to content

Instantly share code, notes, and snippets.

@corburn
Created May 29, 2014 22:00
Show Gist options
  • Save corburn/24b78ad09ecbcf141ff7 to your computer and use it in GitHub Desktop.
Save corburn/24b78ad09ecbcf141ff7 to your computer and use it in GitHub Desktop.
Use AngularJS module in Chrome Extension eventPage
// The first array is an array of angular modules. The ng module is optional.
// It is normally implicitly included and provides access to the angular API.
// The second array is the module components that will be injected as parameters
// to the final element which is a function.
angular.injector(['ng', 'myModule']).inject(['myModuleFactory', ..., eventCtrl]);
// This is where the event handlers are registered
function eventCtrl(myModuleFactory) {
chrome.tabs.onCreated.addListener(myModuleFactory.doStuff);
// ...
}
{
background: {
scripts: [
"bower_components/angular/angular.js",
"js/myModule.js"
"js/eventPage.js"
],
persistent: false
},
manifest_version: 2,
name: "myExtension",
}
angular.module('myModule', [])
.factory('myModuleFactory', function() {
return {
doStuff: function(args) {
// ...
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment