我有两个继承一个基类的组件:
为了对某些方法进行分解,我想从 Base 中调用OnChanges()中Childs的foo() 像这样:
export abstract class Base implements OnChanges{
ngOnChanges(changes: SimpleChanges) {
this.foo();
}
foo(): void{
throw("Error, it shouldn't be instantiated. Override this method.");
}
}
export class ChildA extends Base{
...
foo(): void{
alert("This is the correct method which has to be called !");
}
}
结果是:
错误,它不应该被实例化。覆盖此方法。
不是:
这是必须调用的正确方法!
有人有想法吗?