【发布时间】:2021-01-11 07:16:15
【问题描述】:
我有一个带有 Angular 应用程序的服务类,如下所示:
@Injectable()
export class AbstractStore {
protected url: string;
constructor(protected http: HttpClient) {}
read(url: string): Observable<any> {
return this.http.get<any>(URL + url).pipe(
...
);
}
loadRecords(): Observable<Record[]> {
return this.read(this.url);
}
loadRecord(id: string): Observable<Record> {
return this.read(`${this.url}/${id}`);
}
saveRecord(record: Record): Observable<Record> {
// console statement executes
console.log("Saving record..................", URL + this.url, record);
// THIS NOT EXECUTE
return this.http.post<any>(URL + this.url, record).pipe(
...
);
}
handleError(error) {
console.log(error.message || error);
}
}
当调用读取 (http.get) 方法时,它会正确执行,并且我在“网络”选项卡中看到流量。
当来到saveRecord() 方法时 - 它执行到控制台语句。我没有在“网络”选项卡中看到执行。
我不确定我做错了什么?
【问题讨论】:
标签: angular httpclient