AngularJS 2 Error undefined index1

ぃ、小莉子 提交于 2019-12-10 22:26:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!