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

Commit cf89e86

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 0c3500f commit cf89e86

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: src/auto/injector.js

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

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

Diff for: test/auto/injectorSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,20 @@ describe('injector', function() {
387387
});
388388

389389

390+
it('should configure $provide using an array', function() {
391+
function Type(PREFIX) {
392+
this.prefix = PREFIX;
393+
};
394+
Type.prototype.$get = function() {
395+
return this.prefix + 'def';
396+
};
397+
expect(createInjector([function($provide) {
398+
$provide.constant('PREFIX', 'abc');
399+
$provide.provider('value', ['PREFIX', Type]);
400+
}]).get('value')).toEqual('abcdef');
401+
});
402+
403+
390404
it('should configure a set of providers', function() {
391405
expect(createInjector([function($provide) {
392406
$provide.provider({value: valueFn({$get:Array})});

0 commit comments

Comments
 (0)