From a7bb624ef0f2222334c27c2db0080c676019408b Mon Sep 17 00:00:00 2001 From: Sudhir Jonathan Date: Sat, 24 Nov 2012 03:11:08 +0530 Subject: [PATCH 1/2] Fixes #1452 The `provider` constructor now checks to see if the arguments are an array, which it then instantiates via the `providerInjector`. --- src/auto/injector.js | 3 +++ test/auto/injectorSpec.js | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/auto/injector.js b/src/auto/injector.js index 4f37214da526..1f19320e8c63 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -441,6 +441,9 @@ function createInjector(modulesToLoad) { } function provider(name, provider_) { + if (isArray(provider_)) { + provider_ = providerInjector.instantiate(provider_); + } if (isFunction(provider_)) { provider_ = providerInjector.instantiate(provider_); } diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index d2a637893363..5106c504bab9 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -394,6 +394,17 @@ describe('injector', function() { }); + it('should configure $provide using an array', function() { + function Type() {}; + Type.prototype.$get = function() { + return 'abc'; + }; + expect(createInjector([function($provide) { + $provide.provider('value', [Type]); + }]).get('value')).toEqual('abc'); + }); + + it('should configure a set of providers', function() { expect(createInjector([function($provide) { $provide.provider({value: valueFn({$get:Array})}); From 7252570e3c5884edb2622eea5ac392877109e535 Mon Sep 17 00:00:00 2001 From: Sudhir Jonathan Date: Sat, 24 Nov 2012 03:11:08 +0530 Subject: [PATCH 2/2] fix(injector): Call instantiate for functions and arrays. Fixes #1452 The `provider` constructor now checks to see if the arguments are an array, which it then instantiates via the `providerInjector`. --- src/auto/injector.js | 4 ++-- test/auto/injectorSpec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/auto/injector.js b/src/auto/injector.js index 4f37214da526..c385292b7a9f 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -441,9 +441,9 @@ function createInjector(modulesToLoad) { } function provider(name, provider_) { - if (isFunction(provider_)) { + if (isArray(provider_) || isFunction(provider_)) { provider_ = providerInjector.instantiate(provider_); - } + } if (!provider_.$get) { throw Error('Provider ' + name + ' must define $get factory method.'); } diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index d2a637893363..5106c504bab9 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -394,6 +394,17 @@ describe('injector', function() { }); + it('should configure $provide using an array', function() { + function Type() {}; + Type.prototype.$get = function() { + return 'abc'; + }; + expect(createInjector([function($provide) { + $provide.provider('value', [Type]); + }]).get('value')).toEqual('abc'); + }); + + it('should configure a set of providers', function() { expect(createInjector([function($provide) { $provide.provider({value: valueFn({$get:Array})});