0

I have some data that looks like this in the console:

Here is a screenshot of the console:

enter image description here

In app.component.html

<div *ngFor="let data of queryResult">
      {{data.City}}
</div>

This gives me 1 result when it should give my 615 (See the screenshot of a console.log on the data)

Here is the code in app.component.ts:

async testQuery() {
  const qry = 'SELECT * FROM myTable';
  await this.mysqlService.db.query(qry, (err , result) => {
    if ( err ) {
      console.log('err', err);
    } else {
      this.queryResult = [result];
      console.log(this.queryResult);

    }
  } );
}

How can I make it loop so it show's all of them instead of just 1?

joe2020wow
  • 237
  • 5
  • 12

2 Answers2

2

maybe try this:

<div *ngFor="let record of queryResult">
  <div *ngFor="let data of record">
    {{data.City}}
  </div>
</div>

or try this:

this.queryResult = result;

(no brackets)

Rick
  • 1,710
  • 8
  • 17
1

Use trackby. This solution helped me.

In app.component.html

<div *ngFor="let data of queryResult; trackBy:trackByEmpCode">
      {{data.City}}
</div>

In .ts:

trackByEmpCode(index: number, employee: any): string {
    return employee.City
}
Sahil Ralkar
  • 2,331
  • 23
  • 25