Created
September 13, 2014 10:36
-
-
Save antoniocapelo/6d4b35c500b7fa6494bd to your computer and use it in GitHub Desktop.
Provider Creation in AngularJS
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
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