AngularJS 2错误未定义的索引1 [英] AngularJS 2 Error undefined index1

查看:371
本文介绍了AngularJS 2错误未定义的索引1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现一个MeanStack项目,当我尝试单击按钮更新时出现此错误: 错误:请求的路径在索引1处包含未定义的段

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

有更新服务

 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

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);
    });
  }

推荐答案

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

这篇关于AngularJS 2错误未定义的索引1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆