Recently, I have been developing a service that retrieves a list of users to be used as input for a child component. However, I encountered an issue where the component loads before the users list is fully loaded. One solution I came up with is to implement the *ngIf directive to check if the array is not null. Despite this workaround, I am curious to know if there is a better approach to achieve the desired outcome. Below is a snippet of my code:
private fetchUsersList(): void {
this.usersService.getUsers().subscribe((response: any[]) => {
this.usersList = response;
});
}
Here is my corresponding HTML code snippet:
<users-grid
*ngIf="usersList"
[data]="usersList">
</users-grid>