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

Commit

Permalink
fix($injector): provider can now be defined in the array format
Browse files Browse the repository at this point in the history
`injector.instantiate` is now called for arrays too, instead of only for functions.

Closes #1452
  • Loading branch information
sudhirj authored and pkozlowski-opensource committed Dec 1, 2012
1 parent 8991680 commit 2c405f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/auto/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ function createInjector(modulesToLoad) {
}

function provider(name, provider_) {
if (isFunction(provider_)) {
if (isFunction(provider_) || isArray(provider_)) {
provider_ = providerInjector.instantiate(provider_);
}
if (!provider_.$get) {
Expand Down
14 changes: 14 additions & 0 deletions test/auto/injectorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,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})});
Expand Down

0 comments on commit 2c405f4

Please sign in to comment.