假设我们导入一个Angular Material模块:
providers:[],
imports : [MaterialInput]
在MaterialInput
内,有一个名为:MaterialInputComponent
由于某些原因,我想用我自己的
覆盖该组件所以我希望能够说:
providers:[
{
provide: MaterialInputComponent,
useClass : MyOwnInputComponent
}
],
imports : [MaterialInputModule]
我知道我们可以覆盖这样的服务,但是它也可以用于组件或指令吗?
更新 :
我不是在寻找组件继承,我想要的是使用类似Material Module
的东西,但有时我想覆盖它的组件行为,就像你对服务一样。
喜欢:
如果这是MaterialInput组件背后的原始代码,它位于我的节点模块中。
@Component({})
export class OriginalMaterialInputComonent{
greet(){ alert('Say Aloo'); }
}
我有类似的课程:
@Component({})
export class OverrideMaterialInputComonent{
greet(){ alert('Say yes we can'); } // overriden function
}
而且,我说我导入了一个空洞MaterialInputModule
declarations:[
{
provide: OriginalMaterialInputComonent,
useClass : OverrideMaterialInputComonent
}
],
imports : [MaterialInputModule]
可行吗?
答案 0 :(得分:-1)