1 minute read

Why Should You Opt For Angular Resolvers?

Before a forthcoming component's activatedRoute is active, Angular Resolvers are in charge of directly fetching or removing data from the server. Since the devoted angular developer finds it difficult to go on to the next component without the server data being retrieved, a spinner is not used until the data is fetched.

Let's look at an example to help us better grasp it: in our Angular project, we want to display an array of objects that were received in a component in an unordered list or table.

Advertisement

Let’s say the Angular developer is giving the command *ngIf=” passing some condition” and our business logic depends upon the length of an array, which will be altered once the API call is successful.

As the component will be ready before we receive the data (the array item isn't yet with us), we can run into a problem.

Route Resolver is here to the rescue. Before your component loads, we can retrieve the data using Angular's Route Resolver class. The conditional statements can then function properly with the Resolver at that point.

This article is from: