I have an API made in NODE.JS that brings an object as its response, an image of which I have posted below.
Here is my typescript code that I have in my users.component.ts file.
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent {
users: any[];
constructor(http: HttpClient) {
http.get('url').subscribe(response => {
console.log(response.recordset);
this.users=response.recordset;
});
}
}
And this is the error message that I receive:
src/app/users/users.component.ts:14:28 - error TS2339: Property 'recordset' does not exist on type 'Object’.
14 console.log(response.recordset);
src/app/users/users.component.ts:15:27 - error TS2339: Property 'recordset' does not exist on type 'Object'.
15 this.users=response.recordset;
How do I access this “recordset” property and add it into the users array?
If you do not know the response type of the returned response, you can avoid the error by adding any
which will fix the issue for you.
However best practice would be having the type of the response,
http.get('url').subscribe((response : any) => {