Can you override a third-party module's component declaration?
Say you're using a third-party module that declares and exports two components:
@NgModule({
exports: [Cmp1, Cmp2]
declarations: [Cmp1, Cmp2]
})
export class ThirdPartyModule {}
Cmp1
's template:
`<app-cmp2></app-cmp2>`
Cmp2
's template:
`<p>foo</p>`
AppModule
imports ThirdPartyModule
:
@NgModule({
...
imports: [ThirdPartyModule],
declarations: [AppComponent]
})
export class AppModule {}
AppComponent
's template is just <app-cmp1></app-cmp1>
.
How would you redeclare/override the third-party module's implementation of Cmp2
so that not Cmp2
but MyCmp2
is rendered inside Cmp1
?
Obviously I'd need to extend Cmp2 (or implement its interface):
@Component({
... // same selector as Cmp2
})
export const MyCmp2 extends Cmp2 {}
I tried providing it via DI: { provide: Cmp2, useClass: MyCmp2 }
which didn't work.
Simply declaring it in the app module won't work either, because angular throws when two components match the same selector. Is this even possible?
My specific usecase is overriding the header component of material's horizontal stepper.