【发布时间】:2020-01-27 09:11:04
【问题描述】:
我正在使用服务在组件之间传递数据,我的组件如下所示
constructor(private psService: ProjectShipmentService, private pdComp: ProjectDetailsComponent) {
}
ngOnInit() {
this.psService.getTDate().subscribe(x => this.cachedResults = x);
this.populateArrays();
我的服务在哪里
constructor(private service: DataService, private pInfo: ProjectDetailsComponent) {
this.rProjectNumber = this.pInfo.rProjectNumber;
this.rProjectSO = this.pInfo.rSalesOrder;
this.entityUrl = this.pInfo.entityUrl;
this.tDate = service.get<ShipDateFilterModel[]>(this.entityUrl);
}
即使 tDate 有数据,在 Component 中订阅它时也没有数据。当在 ngOnInIt 生命周期钩子上调用服务时,this.cachedResults 为空。我在这里错过了什么?
【问题讨论】:
-
可能是因为它甚至在您订阅之前就有数据并且在您订阅之后没有发出。
-
@Manish 我如何发出它。
-
在下面查看我的答案,这将解决您的问题..
标签: javascript angular typescript angular7