Search code examples
jsonangularresponsenode-oracledb

Converting JSON response from oracle to angular 2 variable


I am trying to get the get the data from oracle db and displaying it. I have created a service using express api and node and able to run it successfully. I have created angular service to fetch the data, and assign it in angular component, but i am not able to map the JSON response to the angular variable. Please check the code below and help me what i need to change in angular component.ts and how can i use that variable in html.

JSON Data from oracle DB:

[{"COUNT":27}]

angular service:

  getCount(): Promise<String[]> {
    return this.http.get(this.heroesUrl)
               .toPromise()
               .then(response => response.json().data)
               .catch(this.handleError);
  }

angular component.ts

 dataGS : String[];
getData(): void {
    this.dataService
        .getCount()
        .then(dataGS => this.dataGS = dataGS);

Solution

  • Your response does not have a property data, it's just an array. So instead of:

    .then(response => response.json().data)
    

    do:

    .then(response => response.json())
    

    Now you will get your array. Then as proposed by jitender you can iterate your response:

    <div><p *ngFor="let d of dataGS ">{{d}}</p></div>