Skip to content

Instantly share code, notes, and snippets.

@antoniocapelo
Created September 13, 2014 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniocapelo/6d4b35c500b7fa6494bd to your computer and use it in GitHub Desktop.
Save antoniocapelo/6d4b35c500b7fa6494bd to your computer and use it in GitHub Desktop.
Provider Creation in AngularJS
var app = angular.module('capeloMod', []);
app.provider('demo', function() {
var cfg = 'Default';
this.setCfg = function(providedCfg) {
cfg = providedCfg;
};
this.$get = ['dependencyName', function(dependency) {
return new dependency(cfg);
}];
});
// we can now set a custom cfg before the app starts, on the
// configuration phase of the application life-cycle:
app.config(["demoProvider", function(demoProvider) {
demoProvider.setCfg({stuff: true});
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment