There are multiple modules (for example career, departments, and many more) in which I receive data from SQL server through stored procedure (Select query), into the backend which is NEST JS and then into Angular frontend to display those modules (career, departments, etc.) but the problem is that when I click the button then nothing happens, and when I click the button 2nd time then the data displays on webpage. The backend is working fine as I checked in Postman, the data is received the first time. The problem is with the frontend.
Angular Service.ts code:
getdepartments(){
const headers = new HttpHeaders().set('Content-Type', 'application/json').set('Authorization','Bearer'+' '+GlobalService.authtoken);
return this.http.post<any>('http://localhost:3000/employee/getdepartments/',null,{headers}).subscribe(({data}) => {
this.dataout = data});
}
Component.ts code:
departments(){
this.departmentsService.getdepartments();
this.dataout=this.departmentsService.dataout;
}
HTML code:
<div>
<tr>
<th>Departments </th>
<th>Description </th>
</tr>
<tr *ngFor="let index of dataout">
<td>{{index.Department}}</td>
<td>{{index.Description}}</td>
</tr>
</div>
Webpage: