How to create a greyed-out background with Angular Material's MatSpinner

I am currently working on implementing a loader component with the ability to show or hide based on a boolean value in the component's HTML. I have successfully included a matSpinner element, but when embedded in app.component.html, the background does not appear greyed out.

Below is the code snippet from loading.component.html:

<div class="spinner_container"><mat-spinner *ngIf="show"></mat-spinner></div>

The corresponding CSS code for the spinner container is as follows:

.spinner_container {
    border-radius: 10px;
    height: 70px;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%,-50%);
    width: 70px;
    z-index: 3;
    opacity: 0.5;
}

In my app.component.html file, I have placed the loader component alongside other components:

<app-header></app-header>
<app-loader></app-loader>
<router-outlet></router-outlet>

My challenge now is how to disable user interaction with controls behind the spinner until it resolves. Ideally, I would like the application's background to be grayed out during this time to prevent any clicks on controls.

Although the spinner itself functions properly, the issue lies with the accessibility of other controls on the page without being grayed out.

Answer №1

One way to achieve this effect would be:

  .dark-overlay{
    background-color: rgba(0,0,0,0.7);
    position: absolute; <--adjusted as suggested below
    top:0;
    left:0;
    width: 100%;
    min-height:805px; <-- set the height of div or adjust to match page height
}

You can then use a spinner to toggle the display class on and off

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

Is there a way to have text positioned to the left and the right on a single line simultaneously?

Is there a way to format text so that some aligns left and some aligns right on the same line? <p>This text should be aligned left. This text should be aligned right.</p> I can align all text to the left or right, either inline or through a s ...

How can I make the lines of my drawer thicker in Material UI?

Currently, I'm in the process of implementing a left-side navigation bar for a web application I'm developing. The main challenge I'm facing is customizing the styles as desired when using the Drawer component. Specifically, I'm aiming ...

Error with Cloudinary and the <cl-image> component in Angular 5 CLI

Hello there, I am currently in the process of integrating cloudinary into our website. Following the provided guidelines, I have configured it as shown below: app.module ... import { CloudinaryModule } from '@cloudinary/angular-4.x'; import { ...

Ways to prevent the checked value from being continually added to the input text box

I am currently working on a project that involves integrating radio button values with an input field. The purpose of the input field is to enter a name, while the radio buttons are meant for selecting the gender. The default text in the input field shoul ...

Discover the power of sharing a service instance in Angular 2 RC5

In the past, I shared a service instance by declaring it as a viewInjectors within my @Component like so: @Component({ selector: 'my-sel', viewInjectors: [SharedService], templateUrl: 'template.html', pipes: [MyPipe] }) ...

Exploring Angular 5 Nested Loops Using *ngFor and Chunking

I'm new to Angular and working on fetching a nested For-Loop in chunks. <div *ngFor="let eventChunks of chunks(events,3);"> <div *ngFor="let event of eventChunks" class="card-columns"> <event-item [event]="event"></ ...

Utilize Angular to input data into a CRUD table and enhance its value

While working on a CRUD table today, I encountered several errors that are too numerous to mention in the title of the question. Please forgive this oversight. Despite being a simple table and not an Angular material table, I am struggling with debugging i ...

Customize the color when clicking on a mat-slide-toggle

Whenever I click on the element, a shadow appears in the color that corresponds to the element, which is currently yellow https://i.sstatic.net/21BR4.png I would like to change that shadow to be green instead, but I am unsure of how to do so. Here is my ...

Stop angular material css styles from affecting neighboring components

Currently, I have overridden the angular material style in my global SCSS style as follows: .mat-form-field-infix{ padding: 0.5em 0 0.5em 0 !important; } However, I now need to apply a different padding to the same element in my component for addition ...

Enhancing User Experience on Android Devices: Automatic Website Zoom-In Feature for Responsive Design

For the first time, I am delving into creating a responsive website design. I seem to be encountering difficulties when it comes to smartphones. I have been using the following meta-tag to ensure that the website loads "zoomed in". (I found this method on ...

CSS tilt effect for images

I'm currently working on a project where I have two images stacked on top of each other. Using CSS transformations, I want to create a flip effect by first rotating both images away and then bringing the bottom image back in. However, I'm facing ...

Displaying a div within the template based on the type of input parameter

Currently, my situation involves a class hierarchy setup: https://i.sstatic.net/qnOzA.png Within the Angular App, I have a Component in which I take a process as input: @Input() currentProcess: Process I wish to display a different div in the template ...

The input type 'unknown' cannot be assigned to the output type 'string' when utilizing the filter(Boolean) operator

.ts: siteName: string; this.store.pipe( select(getSiteName), filter(Boolean), take(1) ).subscribe(siteName => this.siteName = siteName); Error: Type 'unknown' is not assignable to type 'string ...

Encountering a TypeError in Angular2 and Ionic2: 'Pst.Base64.decode' is not defined when evaluating the object

After upgrading to Ionic2 RC0 from Beta11, which uses ng2 final, I encountered an error while building for ios. The error message states: "EXCEPTION: undefined is not an object (evaluating 'Pst.Base64.decode')." 0 949421 error EXCEPTION ...

I encountered an issue in Angular 2 where an error popped up stating that the name "product" could not be found when I tried

As a beginner in Angular 2, I have been following this tutorial at the link https://www.tutorialspoint.com/angular2/angular2_forms.htm. I have created all the necessary files and code based on the instructions provided. The first file ...

Navigating horizontally to find a particular element

I developed a unique Angular component resembling a tree structure. The design includes multiple branches and nodes in alternating colors, with the selected node marked by a blue dot. https://i.stack.imgur.com/fChWu.png Key features to note: The tree&ap ...

Switch the background image of one div when hovering over a different div

Can anyone assist me with creating an interactive map where continents light up as you hover over them? I am using multiple images within div elements in order to achieve this effect. Specifically, I want to change the background image of one div when hove ...

How to set a default selected value in Angular Material's md-select?

Currently, I am using Angular 2 in conjunction with Angular Material. After reviewing the documentation, my goal is to set a default value for the select field instead of leaving it blank. I have attempted two different methods, but unfortunately, neither ...

What's the reason the background is missing from the entire section?

I am trying to understand why the grey background is not appearing throughout the entire section. I have everything enclosed within the element with the ID of "mid-section". Even though the CSS specifies a grey color for the "mid-section" background, it do ...

The initial Get request does not receive data upon first attempt

In the process of developing an Angular project, I am faced with the task of retrieving data from my backend by making requests to an API. However, before the backend can fetch the required data, certain parameters must be sent through a post request. Once ...