问题
I'm trying to achieve a MeanStack Project, when i'm trying to hit the button update i get this error : Error: The requested path contains undefined segment at index 1
There is the Update Service
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);
});
});
}
the html
<form (submit)="onEditSubmit()">
And the 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);
});
}
回答1:
replace this.router.navigate(['locations/', id]);
to this.router.navigate(['/locations', id]);
来源:https://stackoverflow.com/questions/43396673/angularjs-2-error-undefined-index1