我正在尝试在基类中注入模板服务;从该类派生的类指定了特定的模板类,但是我在不必在派生构造函数中指定注入的情况下就无法注入此服务。
有效方法:
export abstract class BaseDataTableComponent<IDataService> {
constructor(private iDataService: IDataService) {}
}
export class DerivedDataTableComponent extends BaseDataTableComponent<SpecificService> {
constructor (private service: SpecificService) {
super(service)
}
}
我想做什么:
export abstract class BaseDataTableComponent<SpecificService> {
constructor(private iDataService: IDataService) {}
}
export class DerivedDataTableComponent extends BaseDataTableComponent<SpecificService> {
}
我尝试使用Injector在构造函数内部移动注入
export abstract class BaseDataTableComponent<IDataService> {
constructor() {
const injector = Injector.create({providers: [
{provide: IDataService, deps: []}
]});
this.iDataService = injector.get<IDataService>(IDataService);
}
}
但是我收到错误'IDataService' only refers to a type, but is being used as a value here.
,可能是因为我正在尝试使用模板。