我希望在添加新对象“ puits”时更新列表。 所以我需要将我的对象“ pts”作为我刚刚添加的“ puits”,作为订阅的响应,或者也许是另一种方法? 我想我可以使用httpOptions之类的东西来获得对象的目标, 并使用标题的“位置”使用功能get?
//my code in my component :
puits: Puits[] = [];
pts: Puits = {
nom: 'OP100',
idSite: 1,
idtypepuits: 1,
};
ngOnInit() {
this.getPuits();
}
add(nom: string): void {
nom = nom.trim();
if (!nom) { return; }
this.puitsService.addPuits({ nom } as Puits)
.subscribe( pts => {this.puits.push(pts);
});
}
//my code in my service :
addPuits (puits: Puits): Observable<Puits> {
return this.http.post<Puits>(this.puitsUrl, puits, httpOptions).pipe(
tap((newPuits: Puits) => this.log(`Puits ajouté au nom=${newPuits.nom}`)),
catchError(this.handleError<Puits>('addPuits'))
);
}
//my server response when i add a puits :
Location →http://localhost:9090/Base_Puits/Puits/272
Content-Length →0
Date →Thu, 07 Feb 2019 09:54:58 GMT