fix($injector): provider can now be defined in the array format

`injector.instantiate` is now called for arrays too, instead of only for functions.

Closes #1452
This commit is contained in:
Sudhir Jonathan 2012-11-27 00:47:37 +05:30 committed by Pawel Kozlowski
parent 0c3500f532
commit cf89e8653c
2 changed files with 15 additions and 1 deletions

View file

@ -440,7 +440,7 @@ function createInjector(modulesToLoad) {
}
function provider(name, provider_) {
if (isFunction(provider_)) {
if (isFunction(provider_) || isArray(provider_)) {
provider_ = providerInjector.instantiate(provider_);
}
if (!provider_.$get) {

View file

@ -387,6 +387,20 @@ describe('injector', function() {
});
it('should configure $provide using an array', function() {
function Type(PREFIX) {
this.prefix = PREFIX;
};
Type.prototype.$get = function() {
return this.prefix + 'def';
};
expect(createInjector([function($provide) {
$provide.constant('PREFIX', 'abc');
$provide.provider('value', ['PREFIX', Type]);
}]).get('value')).toEqual('abcdef');
});
it('should configure a set of providers', function() {
expect(createInjector([function($provide) {
$provide.provider({value: valueFn({$get:Array})});