【发布时间】:2017-09-09 20:04:00
【问题描述】:
我正在尝试实现一个 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);
});
}
【问题讨论】:
-
您不需要在 router.navigate 调用上使用斜杠 - 应该是:this.router.navigate(['locations', id]);
标签: angular mean-stack