How to use API in app.service.ts in Angular an use its data in the app components

Discussão em 'Angular' iniciado por reza hrkeng, Fevereiro 25, 2025.

  1. reza hrkeng

    reza hrkeng Guest

    I am writing a servise.ts in which used API .But when I want to use its data in a component it's undefined. I used all dependencies

    app.component.ts:
    constructor(private DATA: DataInfoService){}
    this.DATA.ApiService()
    this.Informations = this.DATA.Informations;


    And

    DataInfoService.ts:

    @Injectable({
    providedIn: 'root'
    })...
    constructor(private http: HttpClient) { }
    public ApiService(info: INFO): any {
    var headers = info.headers;
    this.http.post<any>(APIAddress, info.postData, { headers }).subscribe(data => {
    this.Informations = data
    })
    }

    Continue reading...

Compartilhe esta Página