我试图通过 HTTP GET 在一个组件中加载数据,然后我需要在动态加载的子组件中使用这些数据。
这是代码:
ngOnInit(){
this.accountService.getPersonalInfo().subscribe(
response => {
this.Account = response.json();
this.dcl.loadIntoLocation(HeaderComponent, this.elementRef, 'header')
.then(compRef => {
compRef.instance.Account=this.Account;
}
);
}
);
}
在子组件(HeaderComponent)中,我可以this.Account
用来获取这些数据。有一个更好的方法吗?