Angular+ 组件继承 - 在子项中使用订阅



我是 Angular 5 继承的新手,但对 Http 有经验

在常规组件(无继承(中,我对订阅http服务充满信心

我会使用以下

this._MasterService.getRegular('Theodore/portfoliolist')
.subscribe((data: any) => {
this.portfolios = data;
console.log(this.portfolios)
});

在子组件(扩展父组件(中,如果我这样做,它不会记录任何数据

ngOnInit()
{ 
console.log(this.portfolios)
}

有没有办法将父组件中的结果存储到无需订阅即可使用的数组中?

由于子项扩展了父项,因此实际上应该订阅的是该子项。因此,this._MasterService.getRegular(...)移动到子组件的 ngOnInit((。

最新更新