From cf89e8653cd796308d87d75fa9dd1601227fadec Mon Sep 17 00:00:00 2001 From: Sudhir Jonathan Date: Tue, 27 Nov 2012 00:47:37 +0530 Subject: [PATCH] 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 --- src/auto/injector.js | 2 +- test/auto/injectorSpec.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index 84b863b86031..cd47daa67f14 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -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) { diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index 7e5c5d33f2b0..2f82d3b5c689 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -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})});