Wait for subscription to complete

后端 未结 1 2005
傲寒
傲寒 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: ' +  error),
                                           () => console.log('HeatmapData: '+ this.heatmapData.toString());
                                );
    
        }
    

    0 讨论(0)
提交回复
热议问题