我有以下代码来执行http PUT:
updateProduct(form: any) {
this.productService.updateProduct(form, this.id).subscribe(
(data: any) => data
);
this.route.navigate(['']);
}
service.ts:
updateProducts(productForm, id) {
const temp = {
'description': productForm.description,
'quality': productForm.quality
};
return this.httpObj.put(`${this.uri}/products/${id}`, JSON.stringify(temp), {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
});
}
问题是我可以执行更新操作,但是“提交”按钮没有转到原路。
答案 0 :(得分:1)
您需要将router.navigate放在订阅中,
updateProduct(form: any) {
this.productService.updateProduct(form, this.id).subscribe((data: any) => (
this.route.navigate(['']);
)};
};