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