我正在使用Angular 7和rxjs 6。
这是我可观察的数组
private _smsEvents$ = new BehaviorSubject(null);
private smsUrl = environment.baseUrl + 'sms';
get smsEvents$() {
this.GetSmsEvents();
return this._smsEvents$.asObservable();
}
set smsEvents$(value: any) {
this._smsEvents$.next(value);
}
所以我正尝试重新发送SMS事件并仅为此SMS事件更新阵列
GetSmsByID(smsId) {
this.spinnerService.show();
this.http.get(`${this.smsUrl}/get/${smsId}`).subscribe((res: SmsEvent) => {
let tmpList = this._smsEvents$.getValue();
tmpList.forEach(x => {
if (x.ID === res.ID) {
x = res;
}
});
this.smsEvents$ = tmpList;
this.spinnerService.hide();
}, err => {
this.spinnerService.hide();
});
}
ResendSms(smsId) {
this.spinnerService.show();
this.http.get(`${this.smsUrl}/resend/${smsId}`).subscribe(res => {
this.GetSmsByID(smsId);
this.spinnerService.hide();
}, err => {
this.spinnerService.hide();
});
}
我尝试了许多不同的变体来实现(使用重试,计时器,switchMap等)
请帮助:)