我试图实现一个MeanStack项目,当我试图点击按钮更新时,我收到此错误: 错误:请求的路径包含索引1处的未定义段
有更新服务
updateLocation(id, data) {
return new Promise((resolve, reject) => {
this.http.put('https://exemple.herokuapp.com/api/A/'+id, data)
.map(res => res.json())
.subscribe(res => {
resolve(res);
}, (err) => {
reject(err);
});
});
}
html
<form (submit)="onEditSubmit()">
还有component.ts
onEditSubmit() {
this.locationService.updateLocation(this.id,this.location).then((result) => {
let id = result['_id'];
this.router.navigate(['locations/', id]);
}, (err) => {
console.log(err);
});
}
答案 0 :(得分:3)
将this.router.navigate(['locations/', id]);
替换为this.router.navigate(['/locations', id]);