【问题标题】:AngularJS 2 Error undefined index1AngularJS 2错误未定义的index1
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-11-03
    • 2017-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多