Open In App

How to display loading screen when navigating between routes using Angular?

In this post, we will see how to display a loading screen when navigating from one component to another. When the user navigates through routes, the app may communicate with the backend to load some useful data, and it may produce some delay. At that time, if the user doesn’t see anything on the screen, he may think that either the app is broken or something is wrong with the client machine. Hence, it is necessary to keep the user engaged with the app with the help of some message or loading animation.

Prerequisites: NPM must be installed



Environment Setup: We will create a simple app that will simulate some delays while navigation and show a loading spinner while navigating through routes. Let’s quickly set up the environment:

npm install -g @angular/cli
ng new <project-name>

Project Structure: After executing the above commands, you will get a project structure like this:



Project Structure

Now execute these commands:

cd <project-name>
ng serve -o

Output: Open http://localhost:4200 and check whether the default angular landing page is loading or not.

Follow the below steps:

Run the below command:

ng serve -o

Output:


Article Tags :