来自服务响应,需要在另一个组件的ngOnit函数中获取,但在该打字稿中没有 ids
此处 ID 表示
detailvisit(visit: Visit) {
const ids = {
'ID': visit.ID,
'patientid': visit.pid,
};
this.visitService.getavisit(ids);
this.router.navigate(['/detailvisit']);
}
获取记录的服务
getavisit(ids): Observable<Visit> {
const headers = new Headers({ 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + this.authenticationService.token });
const options = new RequestOptions({headers: headers });
return this.http.post('/api/getvisit/', JSON.stringify(ids), options)
.map((response: Response) => {
return <Visit>response.json();
});
答案 0 :(得分:1)
您需要使用.subscribe并将router.navigate放在
中this.visitService.getavisit(ids).subscribe( response => {
console.log("Success Response" + token)
this.router.navigate(['/detailvisit']);
},
error => console.log(error));