Steps to create a personalized loading screen using Angular

I am looking to enhance the loading screen for our angular 9 application. Currently, we are utilizing

<div [ngClass]="isLoading ? 'loading' : ''>
in each component along with the isloading: boolean variable.

Whenever an API call is made, we switch the value of this variable to true which triggers a spinning wheel to appear, freezing the app until the API call completes. Once finished, we set back the value to false and display the content to the user.

I am interested in creating a customized loading screen to provide additional information. Does anyone have any suggestions or solutions for implementing this?

Answer №1

Show a loading spinner using the ngx-spinner library when making calls to a back end service:

Here is an example:

Prior to making the back end call, include this line of code:

this.spinner.show();

In your template, you can add the following:

<ngx-spinner [fullScreen]="true" type="ball-clip-rotate-multiple" size="medium" bdColor="rgba(32, 55, 77, 0.85)">
  <p class="loading" ><Strong>Please wait ...</Strong></p>
</ngx-spinner>

Once the service returns results, use this code:

this.spinner.hide();

Take a look at this demo: https://example.com/demo123

For more information, visit: https://example.com/ngx-spinner-demo

Answer №2

When developing my applications, I always make sure to include a loading state component. It's important to cover all aspects of UI components, including:

  • blank state (Content is loaded but empty, such as an empty list)
  • loading state (Content is still loading)
  • partial state (Certain parts of the view are not yet complete or working on certain elements, like a long list with few entries)
  • error state (Something has gone wrong and cannot be recovered)
  • ideal state (Perfect scenario where content is available and well-structured)

In my approach, I create components specifically for error, loading, and blank states, while incorporating ideal and partial states into other components. By providing inputs, these components can adapt based on contextual information. For instance, in a project view that is empty, a message like "You have no projects yet" could be displayed by the empty state component.

To implement this, you can use:

<ng-container *ngIf="isLoading" ><app-loading-state></app-loading-state></ng-container>
<ng-container *ngIf="error" ><app-error-state [reason]="Failed to load"></app-error-state></ng-container>
<ng-container *ngIf="!isLoading" ><!-- Content of your view here. --></ng-container>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on implementing npm's node-uuid package with TypeScript

Whenever I attempt to utilize node-uuid in TypeScript, I encounter the following issue: Cannot find module uuid This error occurs when I try to import the uuid npm package. Is there a way to successfully import the npm uuid package without encountering ...

After updating my Angular version from 8 to 9, an error has been thrown stating "It is not possible to assign the value 'undefined' to the template variable 'limit'"

Recently, I made updates to my Angular 8 project by switching it to the newest version of Angular 9. In one of the template's div elements, I declared a variable and everything seemed to be functioning correctly without any errors. To avoid initializi ...

What is the best way to extract all Enum Flags based on a Number in TypeScript?

Given: Enum: {1, 4, 16} Flags: 20 When: I provide the Flags value to a function Then: The output will be an array of flags corresponding to the given Enum: [4, 16] Note: I attempted to manually convert the Enum to an array and treat values as numb ...

The static side of the class `typeof _Readable` is erroneously extending the static side of the base class `typeof Readable`

I am currently developing a Discord bot using node/typescript. After running the typescript compiler on my code, I encountered this error: node_modules/@types/readable-stream/index.d.ts(13,15): error TS2417: Class static side 'typeof _Readable' ...

Could one retrieve the value of a type and save it as a constant?

Can I achieve something similar to this: type YesType = true; const myVar = GetTypeValue<YesType>(); // In this instance, the value true is assigned Is it feasible to assign other fixed values to constant variables like in C++? ...

Is it possible to concurrently hot module reload both the server (.NET Core) and client (Angular)?

Using the command 'dotnet watch run' to monitor changes in server code and 'ng build --watch' for Angular code updates has been successful. It rebuilds the code correctly into directories "bin/" and "wwwroot/" respectively. myapp.cspro ...

Angular material mat-calendar multiyear range selection视图

Experiencing an issue with a mat-calendar multiyear view. By default, the dropdown multiyear table displays 3 years back and 20 years forward from the current year (2016, 2017....2030). Instead, I am looking to view 23 years back starting from today' ...

Navigating Angular's Credit Card Input Functionality

I am looking to limit the input capacity to 16 numbers and add a space between each set of 4 numbers. After conducting an extensive search for a credit card input that allows users to enter 16 digits with a " - " or space in between, all results were for ...

Angular powered bootstrap modal with a clean and sleek design featuring a transparent header and background

Currently, I am utilizing an Angular-powered Bootstrap modal for a project. The modal content consists of an iframe that functions as a YouTube video player. My objective is to have the background colors of both the modal body and header be transparent, so ...

What is the best way to include a router-link in a button click event in Angular 8?

Can someone please help me with adding a routing function to a button in Angular? I have already included a (click) function on the button, but how do I actually make the function navigate within the home.ts component? <button class="navbut" (click)= ...

When utilizing gapi (typescript) to send emails, the Sent box may contain incorrectly encoded email messages

When I send emails using gapi, the receiver receives them correctly. However, when I check my "Sent" box, the emails appear as Chinese gibberish characters like in this image. This issue only occurs when using non-gmail applications. If I view the Sent bo ...

I am encountering an issue where Typescript paths specified in the tsConfig.app.json file are not resolving properly

I have defined path settings in my tsconfig.app.json file like this: "paths": { "@app/core": ["./src/app/core"] } Every time I run a test that includes import statements with relative paths, it throws the following error: ...

Is there a way to attach a ref to a Box component in material-ui using Typescript and React?

What is the best way to attach a ref to a material-ui Box component in React, while using TypeScript? It's crucial for enabling animation libraries such as GreenSock / GSAP to animate elements. According to material-ui documentation, using the itemRef ...

Is it possible for Angular templates to be dynamic?

In my component, I have a variable named "myVar" that determines which ng-template should be displayed. Let's consider the following example of a component template: <div *ngIf="myVar; then myVar; else nothing"></div> <ng-template #foo ...

Struggling to map a JSON file in a NextJS project using Typescript

I'm a beginner in JS and I'm currently struggling to figure out how to display the data from a json file as HTML elements. Whenever I run my code on the development server, I encounter the error message: "props.books.map is not a function&q ...

Designing a personalized Angular package for components

I am currently working on developing reusable components that can be utilized across multiple teams. After creating a new Angular project, I went ahead and published it to Azure DevOps artifacts. When attempting to use the component in another project, I ...

Using Node.js and Typescript to bring in external modules from

Attempting to generate a random integer between 1 and 6 using the 'random' library. Here's what I have coded so far: import random from 'random' function rollDice(min:number, max:number) { return Math.floor(Math.random() * (ma ...

Typescript defines types for parameters used in callbacks for an event bus

Encountering a TypeScript error with our custom event bus: TS2345: Argument of type 'unknown' is not assignable to parameter of type 'AccountInfo | undefined'. Type 'unknown The event bus utilizes unknown[] as an argument for ca ...

Using Vue with TypeScript: A Necessary Prop

I recently utilized the vue-property-decorator to add a required prop to my component class. However, when I attempted to use the component without passing the prop, no console errors were displayed indicating that the required prop is missing. Why did thi ...

The storybook is struggling to find the correct builder for the Angular project

I have set up a complex angular workspace with multiple projects. Within the main angular workspace project directory, I have two folders - one for the project application named eventric, and another for a library called storybook. https://i.stack.imgur.c ...