下面是我创建的 AppointmentHelper 类
export class AppointmentHelper {
public static bindAssessements(servicedata: any,
appointmentService: AppointmentService,
serviceDeliveryGuid: string): any {
appointmentService.getAssessments(serviceDeliveryGuid)
.subscribe((response: any) => {
if (response && response.data) {
this.servicedata = response.data
}
}, () => {
// Error Block
});
}
}
在我的主要组件中,我试图像下面这样调用助手类
ngOnInit() {
servicedata :any;
this.serviceDeliveryGuid = '13c22f96-163e-40cf-b13a-e6832154d985';
AppointmentHelper.bindAssessements(this.servicedata, this.appointmentService, this.serviceDeliveryGuid);
}
但是我无法从帮助程序类中获取数据。
所以您能建议我如何获得Helper类对组件的响应并与HTML 7绑定吗?
答案 0 :(得分:0)
您输入错误的内容:
public static bindAssessements(servicedata: any,
appointmentService: AppointmentService,
serviceDeliveryGuid: string): any {
appointmentService.getAssessments(serviceDeliveryGuid)
.subscribe((response: any) => {
if (response && response.data) {
// here should be servicedata = response.data
this.servicedata = response.data
}
}, () => {
// Error Block
});
}
}
也
ngOnInit() {
servicedata :any; // why? you also using this.servicedata in function call
...
}
您是否已在模板中链接了服务数据?
<span>{{ servicedata }}</span>