Last active
February 5, 2017 11:01
-
-
Save mikemclin/505eeb6a983888f9227d to your computer and use it in GitHub Desktop.
Configurable Angular Provider
This file contains hidden or 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('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