Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 2c405f4

Browse files
sudhirjpkozlowski-opensource
authored andcommitted
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
1 parent 8991680 commit 2c405f4

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/auto/injector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ function createInjector(modulesToLoad) {
441441
}
442442

443443
function provider(name, provider_) {
444-
if (isFunction(provider_)) {
444+
if (isFunction(provider_) || isArray(provider_)) {
445445
provider_ = providerInjector.instantiate(provider_);
446446
}
447447
if (!provider_.$get) {

test/auto/injectorSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,20 @@ describe('injector', function() {
394394
});
395395

396396

397+
it('should configure $provide using an array', function() {
398+
function Type(PREFIX) {
399+
this.prefix = PREFIX;
400+
};
401+
Type.prototype.$get = function() {
402+
return this.prefix + 'def';
403+
};
404+
expect(createInjector([function($provide) {
405+
$provide.constant('PREFIX', 'abc');
406+
$provide.provider('value', ['PREFIX', Type]);
407+
}]).get('value')).toEqual('abcdef');
408+
});
409+
410+
397411
it('should configure a set of providers', function() {
398412
expect(createInjector([function($provide) {
399413
$provide.provider({value: valueFn({$get:Array})});

0 commit comments

Comments
 (0)