On thoughtgram blog , I only found examples of DI with service. I want the be able to extend an application by only replacing some services, components, templates and css.
Replacing a component doesn't work. In my example, AppComponent is still using the FooComponent, not the FooOverrideComponent.
I found a solution but it is not very elegant, I would prefer using dependency injection.
class myViewResolver extends ViewResolver{
resolve(component): ViewMetadata {
var view = super.resolve(component);
if (component.name === 'AppComponent') {
view.directives[0] = FooOverrideComponent; //Replace FooComponent by FooOverrideComponent
}
return view;
}
}
bootstrap(AppComponent, [
provide(FooComponent, {useClass:FooOverrideComponent}),
provide(ViewResolver, {useClass:myViewResolver})
]);
Thanks,
Stephane