【发布时间】:2018-03-16 10:03:24
【问题描述】:
我创建了这样一个类
@Injectable FooService {
constructor(private _bar:BarService){
}
}
并像这样扩展它
@Injectable ExtFooService extends FooService {
constructor(private _bar:BarService){
super(_bar);
}
}
这样我得到以下错误:
错误:(12, 14) TS2415:Class 'ExtFooService' 错误地扩展了基类 'FooService'。类型具有私有属性“_bar”的单独声明。
为什么会这样?
我尝试从 ExtFooService 中删除注入,但我在 super() 行得到了这个:
错误:(21, 9) TS2554:Expected 2 arguments, but got 0.
我真的有必要这样做吗?
@Injectable ExtFooService extends FooService {
constructor(private _extBar:BarService){
super(_extBar);
}
}
【问题讨论】:
标签: typescript dependency-injection angular5 extends