我的http服务中有这个方法:
update(field: Field) {
return this.http.put<Field>(`${environment.apiUrl}/fields`, field).pipe(
map((response: any) => {
this.toastr.success(response.message);
return response.model;
}),
);
}
似乎为了从组件调用它,我必须像这样订阅它:
this.fieldService.update(currentField).subscribe(field => console.log(field));
如果我可以这样调用它,我会更喜欢它:
this.fieldService.update(currentField);
作为奖励,我希望能够两者兼得。这可能吗?