Skip to content

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 angular#1452
  • Loading branch information
sudhirj authored and jbdeboer committed Jan 18, 2013
1 parent 9b31f0f commit e8a6564
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 e8a6564

Please sign in to comment.