(英语不是我的母语,所以请原谅我) 嘿,我是Angular的新手,我正在尝试发出一个http请求,当我单击一个按钮时(例如),我删除了一个医生,并且知道我在为使代码正常工作所必须做的事情上苦苦挣扎。谢谢
这是doctor.service.ts
getDoctor(doctorId: string): Observable<Doctor> {
return this.http.get<Doctor>(`${this.apiUrl}/${doctorId}`, {headers})
.pipe(map((doctor: Doctor) => {
return doctor;
}), catchError((error: any) => {
this.getError(error);
return of<Doctor>(EMPTY_DOCTOR);
}));
}
deleteDoctor(DoctorId: string): Observable<void> {
return this.http.delete<void>(`${this.apiUrl}/${DoctorId}`, {headers})
}
答案 0 :(得分:0)
如果要使用deleteDoctor()
方法,则应调用可观察对象的subscription方法:
deleteDoctor(DoctorId: string): Observable<void> {
this.http.delete<void>(`${this.apiUrl}/${DoctorId}`, {headers})
.subscribe(response => {
// Do something here if needed...
});
}
您还可以保留您的方法并以这种方式调用它:
this.deleteDoctor().subscribe(response => {
// Do something here if needed...
});