簡體   English   中英

在 DELETE Web API 后調用 GET Web API 已在 Angular 完成

[英]Calling GET Web API call after DELETE Web API has finished in Angular

這是我的代碼:

if (confirm("Are you sure you want to delete the contact?")) {
    this.http.delete(this.apiRoot + id)
        .subscribe()

    this.loadContacts()
        .subscribe(); 
}                           

嘗試了很多東西,但基本上我希望 Web API 方法在調用 loadContacts() 之前返回

如果您想“等待”直到刪除請求完成,您可以使用switchMap RxJS 運算符。

this.http.delete(this.apiRoot + id).pipe(
    switchMap(() => {
        return this.loadContacts();
    })
).subscribe();

當外部對象發出值時,這將切換到內部可觀察對象。 更多信息可以在 Learn RxJS網站上找到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM