I have a method that makes a query and gets some data.
I know that the data is there because console.log is showing it but it's not been passed to the variable I created so I have add it to an *ngFor loop in the .html of the component.
Here is the code:
...
export class MainComponent {
queryResult; // results wanted here
constructor(private myService: MyService) {
this.testQuery(); // run the method
}
testQuery() {
const qry = 'SELECT * FROM mytable';
this.myService.db.query( qry, ( err, result ) => {
if ( err ) {
console.log('err', err);
} else {
console.log('result', result); // shows the data
this.queryResult = result; // result is NOT passed to this.queryResult
}
} );
}
How can I pass the result data to this.queryResult?
UPDATE:
I've checked this.queryResult is there's is actually data there.
It looks like this:
console.log(this.queryResult);
And it's returning this:
Is it something to do with the *ngFor then?
Here's that part:
<ul>
<li *ngFor="let data of queryResult">
{{data.City}}
</li>
</ul>