mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
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
This commit is contained in:
parent
0c3500f532
commit
cf89e8653c
2 changed files with 15 additions and 1 deletions
|
|
@ -440,7 +440,7 @@ function createInjector(modulesToLoad) {
|
|||
}
|
||||
|
||||
function provider(name, provider_) {
|
||||
if (isFunction(provider_)) {
|
||||
if (isFunction(provider_) || isArray(provider_)) {
|
||||
provider_ = providerInjector.instantiate(provider_);
|
||||
}
|
||||
if (!provider_.$get) {
|
||||
|
|
|
|||
|
|
@ -387,6 +387,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})});
|
||||
|
|
|
|||
Loading…
Reference in a new issue