我们如何从Helper类到组件获得响应并在角度7中与HTML绑定?

问题描述 投票:0回答:1

下面是我创建的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类到组件的响应以及在角度7中与HTML绑定?

angular angular-services
1个回答
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
  ...
}

你有没有在模板中链接servicedata?

<span>{{ servicedata }}</span>
© www.soinside.com 2019 - 2024. All rights reserved.