简体   繁体   English

我们如何获得Helper类对组件的响应并在angular 7中与HTML绑定?

[英]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.

相关问题 Angular2:组件如何绑定到类? - Angular2: how can component bind to class? 我们如何使用node.js从angular 7应用程序中的mysql数据库中获取数据并将其显示在angular组件html页面上 - How can we get data from mysql database in angular 7 application by using node.js and display it on angular component html page 如何将图像从App Component绑定到Angular 2中的HTML文件 - How to bind an Image from App Component to HTML file in Angular 2 angular:如何从本地组件访问应用程序根目录中的类名? - angular: how can we access the class name in the app-root from local component? 我们如何将输入模型类中的每个更改从 Angular 13 中的子组件推送到父组件 - How can we push each changes in input model class to parent component from child in Angular 13 如何获取响应(json数组)并将其放在Angular 4中的我的html组件中 - How to get response (array of json) and put it in my html component in Angular 4 角度组件和助手服务或助手类 - angular component and helper service or helper class 如何在 angular 2 中绑定 HTML 中组件的静态变量? - How to bind static variable of component in HTML in angular 2? 我们可以将html模板从angular2中的一个组件传递到另一个组件吗? - Can we pass html template from one component to another component in angular2? 如何让Angular2绑定innerHTML中的组件 - How to get Angular2 to bind component in innerHTML
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM