I am able to get data from the REST API in my application, i am able to print the data on to the console, but no idea how do i display on to html, can any one help me on this please?
App.component.ts
import { HttpClient } from '@angular/common/http';
import { Component, Inject } from '@angular/core';
import { Employee } from './employee';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'emp-data-example';
employees:Employee[]=[];
constructor(@Inject(HttpClient) private http:HttpClient){
}
ngOnInit(){
this.http.get("http://localhost:8080/api/all").subscribe(
response=>{
this.employees=response; // here is error because response is an Object and employees is an array
});
//resp.subscribe((data)=>{this.employees=data});
}
}
app.component.html
<div>
<table border="1">
<tr>
<th>Emp Id</th>
<th>Emp Name</th>
<th>Salary</th>
</tr>
<tr ngFor="let employee of employees">
<td>{{employee.id}}</td>
<td>{{employee.name}}</td>
<td>{{employee.department}}</td>
<td>{{employee.salary}}</td>
</tr>
</table>
</div>
this.employees=[response];
– firatozcevahir Dec 3 '20 at 5:51Employee
model has the properties – firatozcevahir Dec 3 '20 at 6:11