I have a code that returns objects below after calling an API:
{"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":""},
{"id":"3","employee_name":"Ashton
Cox","employee_salary":"86000","employee_age":"66","profile_image":""}
This is the code block that retrieves the data:
myEmployees: Employee[];
getEmployees() {
this.http.get<Employee[]>('http://dummy.restapiexample.com/api/v1/employees')
.subscribe((response) => {
this.myEmployees = response;
console.log(this.myEmployees);
});
}
I have also created a class Employee as below:
export class Employee {
id: any;
employee_name: any;
employee_salary: any;
employee_age: any;
profile_image: any;
}
I want to store the results retrieved in an array of type Employee and then display an alert for each employee in the array. I am not very familiar with typescript, I tried the below but does not seem to work. I cannot access the properties of Employees. Anyone know how this can be achieved?
for (let m of this.myEmployees) {
alert(m.employee_name);
}