有没有办法从抽象服务调用子类方法?当我这样做时,语句不会执行,因为不存在。我不确定为什么它不存在。也许有一种“有角度”的方式来做到这一点,而不是在初始化时触发它。或者,也许我只需要在组件中手动调用 onInit。基本上,我正在做的是尝试从服务器获取初始应用程序数据。ifonInit
@Injectable({providedIn:'root'})
export class RootService {
public constructor(httpClient: HttpClient) {
if(typeof this.onInit === 'function') {
this.onInit()
}
}
}
@Injectable({providedIn:'root'})
export class MyService extends RootService {
public onInit() {
// Do stuff
}
}
@Component()
export MyComponent {
public constructor(myService: MyService) {}
}
守候你守候我
扬帆大鱼
相关分类