【发布时间】:2019-01-07 16:57:28
【问题描述】:
删除功能不再起作用。
我从 Delete HTTP 调用中删除了我的信息,它可以工作,但是当我在 angular2 部分前端使用时,它不再工作了。
错误 删除http://localhost:3001/formations/undefined0()
例外:响应状态:0 对于 URL:null
Subscriber.js:246 Uncaught Response {_body: ProgressEvent, status: 0, ok: false, statusText: "", headers: Headers, ...}
zone.js:2019 删除http://localhost:3001/formations/undefined0 ()
这是我的队形。服务
deleteFormation(id){
return this.http.delete("http://localhost:3001/formations/"+id)
.map(res => res.json());
}
这是我的家。ts
import { Component, OnInit } from '@angular/core';
import { FormationService } from '../../services/formation.service';
import { Formation } from '../../../app/formation';
import {Observable} from 'rxjs/Rx';
@Component({
selector: 'app-home1',
templateUrl: './home1.component.html',
styleUrls: ['./home1.component.css']
})
export class Home1Component implements OnInit {
formation: Observable<Formation[]>;
constructor(
public formationService:FormationService
) { };
ngOnInit() {
this.formation = this.formationService.getFormations();
// this.getFormations();
}
getFormations(){
this.formationService.getFormations()
.subscribe(formation=>{
this.formation = this.formation;
})
}
deleteFormation(id) {
this.formationService.deleteFormation(id)
.subscribe(()=>{
this.getFormations();
});
}
}
这是我的家.html
<app-navbar1></app-navbar1>
<table class="table table-bordered">
<thead>
<tr>
<td><b>Title</b></td>
<td><b>url</b></td>
<td><b>description</b></td>
<td width="275" align="center"><b>Action</b></td>
</tr>
</thead>
<tbody>
<tr *ngFor="let forms of formation | async " >
<td>{{forms.title}}</td>
<td>{{forms.url}}</td>
<td>{{forms.description}}</td>
<td width="275">
<a class="btn btn-info" routerLink="/show/{{formation._id}}">Detail</a>
<a class="btn btn-success" routerLink="/edit/{{formation._id}}" >Edit</a>
<a class="btn btn-danger" (click)="deleteFormation(formation._id)" >Delete</a>
</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
不知何故,您的 id 未定义。检查组件中调用deleteFormation方法的视图是否传递了正确的id。
标签: node.js angular angular2-routing