我有 getResponseCount()方法,该方法在页面加载时运行。其中一种方法是花费超过4分钟的时间从后端获取数据(其余方法在不到3秒的时间内执行)。我正在加载微调框,直到所有方法都执行完为止。因此,微调器几乎要加载4分钟以上。一旦所有方法执行完毕,微调器将被隐藏。现在,我想使该特定方法在后台运行(异步)。微调框不应等待此方法执行。如何做到这一点。 我在下面附加了示例代码:
ngOnInit() {
this.loadControls();
this.loadApps();
this.loadReults();
this.getResponseCount();
this.loadPreferences();
}
private async getResponseCount() {
this.services.getResponseCount().subscribe(
result => {
this.Count = Number(result);
this.spinnerService.hide();
},
error => {
this.handleError('Error Retrieving Partitions count.', error),
this.spinnerService.hide();
});
return;
}
private loadApps() {
this.service.loadApps().subscribe(
result => {
if (result) {
result.push('cloud');
}
this.app = result;
},
errorGetApp => {
this.handleError('Error Retrieving apps.', errorGetApps),
this.spinnerService.hide();
},
() => {
this.siteFilteredOptions = this.appControl.valueChanges.pipe(
startWith(''),
map(value => this.appFilter(value))
);
}
);
}
private loadReults() {
this.logViewerService.loadReults().subscribe(
response => {
this.ReultsList = response;
},
errorRun => {
this.handleError('Error getting Reults.', errorRun),
this.spinnerService.hide();
}
);
}
private loadControls() {
this.service.getQuery().subscribe(
response => {
this.loadControls(response);
},
error => {
this.handleError('Error getting query.', error),
this.spinnerService.hide();
},
() => this.resultsComponent.loadResults(paramQueryId)
)
} else {
this.loadPreferences();
}
private loadPreferences() {
this.logViewerService.getPreferences().subscribe(
response => {
this.loadPreferences(response);
this.buildQuery();
},
error => {
this.handleError('Error getting Preferences.', error);
this.spinnerService.hide();
}
);
}