[英]How we can get response from Helper class to component and bind with HTML in angular 7?
下面是我创建的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
});
}
}
在我的主要组件中,我试图像下面这样调用helper类
ngOnInit() {
servicedata :any;
this.serviceDeliveryGuid = '13c22f96-163e-40cf-b13a-e6832154d985';
AppointmentHelper.bindAssessements(this.servicedata, this.appointmentService, this.serviceDeliveryGuid);
}
但是我无法从助手类中获取数据。
因此,您能否建议我如何才能从Helper类获得对组件的响应并在angular 7中绑定HTML?
您输入错误:
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
...
}
您是否在模板中链接了servicedata?
<span>{{ servicedata }}</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.