I am using Angular 7 and facing an issue => after login the API GET calls successfully and the component receiving data too, but UI is not displaying that data.
When I open the browser console, immediately the data gets populated on the UI and a warning is showing in the console.
"core.js:15686 Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?"
I have googled this warning and found some workaround like this.ngZone.run()
and call my API's inside it.
But the issue is, I am using more than 40 components and calling so many API in each component. So I have to call ngZone.run()
on each API call, which seems to be difficult to do.
What's the better approach to overcome this issue?
app.component.ts
getEmployees(): void {
this.employeeService.getEmployees().subscribe(e => {
this.employees = e;
});
}
app.service.ts
@Injectable()
export class EmployeeService {
constructor(private httpClient: HttpClient) { }
getEmployees() {
return this.httpClient.get<EmployeeModel[]>('employees');
}
getEmployees
. From where are you callinggetEmployees(): void
– Weilemployees
when set inapp.component.ts
? – AutodidactgetEmployees()
get called?Is that called directly by some click, or it is wrapped inside some callbacks? – Disproof