AngularJS 2错误未定义index1

时间:2017-04-13 15:49:24

标签: angular mean-stack

我试图实现一个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);
    });
  }

1 个答案:

答案 0 :(得分:3)

this.router.navigate(['locations/', id]);替换为this.router.navigate(['/locations', id]);