Wait for subscription to complete

后端 未结 1 1990
傲寒
傲寒 2021-01-20 07:16

I have a simple scenario: I want to store an array returned from a service into a class variable. How do I wait for the data to be available until I store the data? It is a

相关标签:
1条回答
  • 2021-01-20 07:53

    You can just do it on complete() function. Doing that you will ensure that the data has arrived first.

        getEventHistory(): void {
        this.eventHistoryService.getEventHistory()
                                .subscribe(data =>  this.heatmapData = data,
                                           error => console.log('Error in Heatmap get data: ' + <any> error),
                                           () => console.log('HeatmapData: '+ this.heatmapData.toString());
                                );
    
        }
    
    0 讨论(0)
提交回复
热议问题