I have an action to go back, when button is clicked I need to do an api call to delete all items and then go back in another page.
So in my html:
<a class="btn backbtn" (click)="goBack()" role="button">
Back
</a>
goBack(){
removeItems = this.removeAllItems(this.items)
if(removeItems) this.router.navigate(["/home"])
}
removeAllItems(items){
items.forEach((item) => {
let removeItemService = this.itemService.removeItem(item.id)
removeItemService.pipe(untilDestroyed(this)).subscribe(
(data) => {console.log("data", data)}
)
if (products.length === 0) return true
})
}
In my service:
removeAllItems(itemId): Observable<any>{
let url = ..... + itemId
return this.http.delete(url)
}
Now the problem is that it doesn't enter in
if(removeItems) this.router.navigate(["/home"])
So items are not deleted