Can we inject different provider while loading components dynamically?
my-component
  @Component({
     moduleId: module.id,
     selector: "my-component",
     template: "<div>my-component</div>",
     providers: [MyComponentService]
  })
  export class MyComponent{
     constructor(private ds: MyComponentService) {
        super();
     }    
   }
some where else,
     this._cr.resolveComponent(MyComponent).then(cmpFactory => {
        let instance: any = this.testComponentContainer.createComponent(cmpFactory).instance;
    });
so in above code, while resolving MyComponent, provider for this MyComponentService will also be resolved, can we resolve it differently based upon some switch?
                        
ViewContainerRef.createComponent
has an
injectorparameter. If you pass one this one is used to resolve providers. I don't think you can override providers added to the@Component()decorator though.You can create a new injector Injector
and pass this injector or you can inject the injector to the component that calls
ViewContainerRef.createComponentand create a child injector.Injectoris the generic base classReflectiveInjectoris a concrete implementation.This way the providers that are available to the current component are passed along and
Car, andChildare added. Therefore providers thatchildcan't resolve (others thanCarandEngine) are tried to resolve from the parent injector.Plunker example