在组件中,如果我尝试做console.log(病人)是看到一个xml表示的对象进入我的控制台但是如果我尝试从返回的对象绑定我的组件中的数据我无法假设我在模板部分中的组件{{patient.Patient_Name}}但是我无法看到组件中的数据?
@Component({
selector: 'dashboard-thumbnail',
template: <h2>Name:{{patients.Patient_Name}}</h2>
})
export class DashboardThumbnailComponent {
patients : Patient
constructor(private dashboardService : DashboardService, private activatedRoute: ActivatedRoute){}
ngOnInit(){
this.dashboardService.getPatient(+this.activatedRoute.snapshot.params['id']).subscribe((patient) => {
this.patients.Patient_Name = patient.Patient_Name;
在此输入代码
console.log(patient);
})
}
}
答案 0 :(得分:0)
经过大量研究后我理解,我的getPatient方法的返回类型是一个数组,所以要绑定数据,我必须循环遍历患者对象,而不是直接绑定它。希望这有帮助!!
enter code here<div *ngFor = "let patient of patients" class = "well hoverwell thumbnail" >
<h2>Name : {{patient.Patient_Name}}</h2>