Skip to content

Instantly share code, notes, and snippets.

@mikemclin
Last active February 5, 2017 11:01
Show Gist options
  • Save mikemclin/505eeb6a983888f9227d to your computer and use it in GitHub Desktop.
Save mikemclin/505eeb6a983888f9227d to your computer and use it in GitHub Desktop.
Configurable Angular Provider
var app = angular.module('app', []);
app.provider('MyConfig', function () {
var config = {
foo: 'bar'
};
return {
settings: function (userConfig) {
angular.extend(config, userConfig);
}, $get: function () {
return config;
}
};
});
app.config(function (MyConfigProvider) {
MyConfigProvider.settings({
foo: 'baz'
});
});
app.controller('AppCtrl', function ($scope, MyConfig) {
$scope.foo = MyConfig.foo;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment