Seeking to extract information from a test URL and convert the data into a list, I aim to exhibit them in an alert/Loop for testing purposes. The dummy API URL being used is:
The returned data follows this structure:
{"status":"success","data":[{"id":"1","employee_name":"Tiger Nixon","employee_salary":"320800","employee_age":"61","profile_image":""},{"id":"2","employee_name":"Garrett Winters","employee_salary":"170750","employee_age":"63","profile_image":""} ...
Displayed below is the TypeScript code segment:
constructor(private http: HttpClient) { }
configUrl = 'http://dummy.restapiexample.com/api/v1/employees';
getEmployees() {
var x = this.http.get<Employee[]>('http://dummy.restapiexample.com/api/v1/employees').pipe(map(res => res['data']));
alert(JSON.stringify(x));
}
This represents the Employee class utilized:
export class Employee {
id: any;
employee_name: any;
employee_salary: any;
employee_age: any;
profile_image: any;
}
According to my exploration, one should apply pipe(map(res =>res['data']), however, it isn't functioning correctly in my case. Any assistance in comprehending what might be incorrect with the aforementioned code would be greatly appreciated.