How to add providers to Injector dynamically?
问题 Each component can specify new Provider s using its providers property in ComponentMetadata . Is there a way to specify providers dynamically from, say, constructor of the component? 回答1: I've done it in the bootstrap part. bootstrap(AppComponent,[ provide( RequestOptions, { useClass: DefaultRequestOptions } ), provide(Http, { useFactory: function(backend, defaultOptions) { return new Http(backend, defaultOptions); }, deps: [XHRBackend, RequestOptions]}), ]); I'm guessing it can be done in a