When you register provide(Foo, ...), , than you can
constructor(foo:Foo)
with multi: true you will get all providers registered as Foo
constructor(foo:any)
WITH
export const FOO_PROVIDERS = [ provide(Foo, { useClass: Foo, multi: true }), provide(Foo, { useValue: HTTP_PROVIDERS, multi: true }) ];
and
constructor(@Inject(Foo) foo:Foo[])
you will receive an array passed to Foo containing an instance of Foo , and as a second element, a list of providers (they are contained in HTTP_PROVIDERS )
Update
You may have different expectations about what should happen. I do not see here as @Inject(Http) http . HTTP_PROVIDERS is only registered as a value for Foo . What value you switch to useValue does not matter when the providers are allowed. DI looked for suppliers for Foo and passed the assigned value, and no matter what that value is. In your example, there is no Http provider, so Foo itself could not get Http . You will need to register Http , which will be done if you add HTTP_PROVIDERS directly to providers (not in useValue ), because HTTP_PROVIDERS contains Http (which is equivalent to provide(Http, {useClass: Http})
Update2
}
source share