The mat-spinner is continuously spinning without stopping

I am facing an issue with a component (dialog-component) that references another component (DATA-component). In the dialog-component-ts file, when I set

isLoaded = false 

and then use

this.isLoaded.emit(true);

in DATA-component, the isLoaded value in dialog-component-ts is correctly set to true. However, the mat-spinner keeps spinning and the loaded data is not displayed. Interestingly, I have similar code in other components where it works perfectly fine. On the other hand, when I set

isLoaded = true 

in dialog-component-ts, the spinner disappears and the data shows up as expected. Any insights on what might be causing this issue?

dialog-component-html:

 <mat-card>
    <div *ngIf="!isLoaded" fxLayout="row" fxLayoutAlign="center center" class="loading">
      <mat-spinner></mat-spinner>
    </div>
    <app-data *ngIf="selectedDialogData === enum1" [fxShow]="isLoaded"
                       (title)="onComponentTitleChange($event)"
                       (isLoaded)="onComponentReadyStateChange($event)"
                       (dialogDataChanged)="onSelectedDialogDataChange($event)">
    </app-data>
 </mat-card>

dialog-component-ts:

@Component({
  selector: 'app-dialog',
  templateUrl: './dialog.component.html',
  styleUrls: ['./dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})


export class DialogComponent {

  constructor(
    @Inject(MAT_DIALOG_DATA) public dialogData: SomeModel) { }

  public isLoaded = false;
  
...

  public onComponentReadyStateChange(state) {
    this.isLoaded = state;
  }
...

data-component-ts:

@Component({
  selector: 'app-data',
  templateUrl: './data.component.html',
  styleUrls: ['./data.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class WorkingtypeDataComponent implements OnInit {

  @Output() title = new EventEmitter<string>();
  @Output() isLoaded = new EventEmitter<boolean>();
  @Output() dialogDataChanged = new EventEmitter<EnumList>();

  constructor(@Inject(MAT_DIALOG_DATA) public dialogData: SomeModel,
              private dialogRef: MatDialogRef<DialogComponent>,
              private formBuilder: FormBuilder,
              private Service: SomeService,
              private dialog: MatDialog) { }


  ngOnInit(): void {
    this.isLoaded.emit(false);
    this.currentElement = this.dialogData.changeElement;
    this.alreadyExistingElementNames = this.dialogData.alreadyExistingElementNames;
    this.isEditing = this.currentElement.name != null;
    const title = `texts.${this.isEditing ? 'edit' : 'add'}`;
    this.title.emit(title);
    this.isLoaded.emit(true);
  }

Answer №1

When implementing the ChangeDetection.OnPush strategy in Angular, change detection is only performed when changes are detected in the @Input properties.

In order to respond to changes in child Outputs, you must manually trigger a change detection cycle.

One way to do this is by using the this.cdr.detectChanges() method.

Comprehensive Guide

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

"Learn the trick to selecting a material checkbox by simply clicking on the table cell (td)

Is there a way to have a checkbox automatically checked when clicking on a table cell? I attempted to use a reference variable, but encountered an error. Error message: DetailComponent.html:97 ERROR TypeError: jit_nodeValue_15(...).click is not a func ...

What steps can be taken to establish an array type that is limited to predefined values?

I am currently working on defining a type for an array that requires specific values to be present in a certain order at the beginning of the array. type SpecificArray = ('hello'|'goodbye'|string)[] // Current const myArray: SpecificAr ...

There was an issue encountered while attempting to differentiate an object in the Angular datatable results. The data table only accepts arrays and iterables

Looking to retrieve user data from an API using the httpClient post method in Angular 5, I faced a challenge as I couldn't properly display the retrieved information in a datatable. Below are snippets of the code that I have experimented with: User ...

Learn how to implement React Redux using React Hooks and correctly use the useDispatch function while ensuring type-checking

I'm curious about the implementation of Redux with Typescript in a React App. I have set up type-checking on Reducer and I'm using useTypedSelector from react-redux. The only issue I have is with loose type-checking inside the case statements of ...

What causes the error "Angular 2 checkbox params.setValue is not functioning properly"?

import { Component } from '@angular/core'; import { GridOptions, RowNode } from 'ag-grid/main'; import { ICellRendererAngularComp } from 'ag-grid-angular'; @Component({ selector: 'qrp-drop-down-selector', ...

Creating a higher order component (HOC) that utilizes both withRouter and connect functions in React

I am currently working with the following stack: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87f5e2e6e4f3c7b6b1a9b6b4a9b6">[email protected]</a> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" dat ...

Bringing @angular/code into a directory that is not within an Angular project

Currently, I have an Angular 2 project folder with a separate service folder named "auth.service.ts" located outside of it. Within this service file, I am importing `Injectable` from `@angular/core`. However, due to the service being located outside of t ...

Error: "the cart variable in the ctx object has not been defined"

A project I'm currently working on involves a pizza ordering app, and my current focus is on implementing the Cart feature. Each user has their own cart, which includes specific details outlined in cart.ts import { CartItem } from './cartitem&a ...

Creating a record type with specific keys associated with values while leaving the rest undefined

Consider the scenario where the following code is implemented: const myObj = { "hello": "world"; } as const; const anyString: string = "Hi" if (myObj[anyString]) { // Element implicitly has an 'any' type because ...

Launching Node Application

While working with NestJS and IIS, I encountered an issue when deploying my 'dist' folder on the server using IISNode. The error message 'module not found @nestjs/core' prompted me to install the entire 'package.json' files (n ...

Can we limit the return type of arrow function parameters in TypeScript?

Within my typescript code, there is a function that takes in two parameters: a configuration object and a function: function executeMaybe<Input, Output> ( config: { percent: number }, fn: (i: Input) => Output ): (i: Input) => Output | &apos ...

Having trouble compiling an Ionic/Cordova app for Android?

I have encountered an issue while trying to build my Ionic/Cordova app for Android. It runs smoothly on iOS, but when attempting to build for Android, I keep receiving an error message. The specific error is: Error: Attribute meta-data#android.support.V ...

I'm curious about the equivalent of "ng serve" for nodejs. Do other languages have similar tools available?

ng serve has revolutionized my workflow. With a simple save, I can instantly see the changes in my Angular code reflected in the running instance of my project, allowing me to quickly iterate on my work. But why doesn't a similar tool exist for other ...

Leveraging TypeScript for defining intricate tree manipulation guidelines

In my current project, I am working on enhancing a TypeScript process that is in place. The goal is to make it more strongly typed for better scalability and accuracy. The structure of the existing tree under consideration is as follows: interface Node { ...

Unable to access the inner object using key-value pair in Angular when working with Firebase

Within my json object, there is an inner object labeled data, containing {count: 9, message: "9 sites synced"} as its contents - also in json format. My objective is to extract the value from message, rather than count. Provided below is the temp ...

Angular - Verify the presence of queryParams on the root path (/)

I have a legacy application built in Vaadin that requires migration to Angular 15 while maintaining the same URL structure. The transition is nearly complete, with one crucial task remaining: identifying if there are no URL query parameters present on the ...

Utilizing Window function for local variable assignment

Currently, I am facing a challenge in my Angular2 service where I am attempting to integrate the LinkedIN javascript SDK provided by script linkedin. The functionality is working as expected for retrieving data from LinkedIN, however, I am encountering an ...

Utilizing Angular to Handle Undefined Variables in String Interpolation

Seeking a way to showcase data obtained from an external API on a webpage using Angular's string interpolation. If no data is retrieved or is still pending, the aim is to display 'N/A'. An attempt was made following this method, but encoun ...

What could be the reason for encountering an "Uncaught Runtime Error" specifically on an Android emulator while using a React app?

I'm encountering an issue when trying to launch a web-based React app on Chrome within an Android emulator. The error message I'm receiving is as follows: "Unhandled Runtime Error Uncaught SyntaxError: Unexpected Token ." Interestingly, the same ...

What methods can you use to identify obsolete or inactive code within an Angular project?

For over a year, my team and I have been dedicated to developing an innovative angular application. As we engage in the ongoing process of code refactoring, our objective is to eliminate any unnecessary or obsolete code from our repository. We are seeking ...