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

fix($injector): provider can now be defined in the array format #1611

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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