Issue
i am working in an Angular Material Dialog, what i want to do is a patch request when i close the Dialog.
In my component i have a property that like this, with a certain data i receive with @input
public stat:Stat = {
id: "",
_id: "",
name: "",
bithplace: "",
institution: "",
topics: [],
maininterest: "",
img: "",
index: ''
}
I want to filter the data so i can get only the properties that changed and the index to make the patch request.
const dialogRef = this.dialog.open(DialogUpdateComponent, dialogConfig)
dialogRef.afterClosed()
.pipe(
filter( (resp) => Object.values(resp) !== Object.values(this.stat) && resp.index)
)
.subscribe
(resp => this.statService.editStat(resp, resp.index))
}
At this point i think i should have the data i want, but when i execute the code nothing happens.
This is the editStat method:
editStat(stat: Stat, index:string):Observable<Stat>{
return this.http.patch<Stat>(`${this.basic_URL}/${index}`,stat)
}
When i make the patch request in Postman, changing a property in the body it works, but this doesnt happen in my app when i close the dialog.
Solution
Observables need subscribed to. What you're missing is the subscribe. Best way to handle that is to concatMap over to it.
const dialogRef = this.dialog.open(DialogUpdateComponent, dialogConfig)
dialogRef.afterClosed()
.pipe(
filter( (resp) => Object.values(resp) !== Object.values(this.stat) && resp.index)),
concatMap((resp) => this.statService.editStat(resp, resp.index)),
)
.subscribe();
Answered By - Wesley Trantham
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.