I've been using angular with material, and I want to have the 'mat-progress-bar' show when I press 'Add' on my dialogbox I've made a small app on StackBlitz which might make it easier to understand.
https://stackblitz.com/edit/angular-eqxkbm
dialog-overview-example.html
<div *ngIf="LoadingCondition; then LoadingBlock"></div>
<ng-template #LoadingBlock><mat-progress-bar mode="indeterminate"></mat-progress-bar></ng-template>
<br>
My list list here
<br>
<br>
<button mat-raised-button (click)="openDialog()">Add</button>
dialog-overview-example.ts
import {Component, Inject} from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export interface DialogData {
animal: string;
name: string;
}
@Component({
selector: 'dialog-overview-example',
templateUrl: 'dialog-overview-example.html',
styleUrls: ['dialog-overview-example.css'],
})
export class DialogOverviewExample {
public LoadingCondition = false;
animal: string;
name: string;
constructor(public dialog: MatDialog) {}
openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: {name: this.name, animal: this.animal}
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
this.animal = result;
});
}
}
@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
})
export class DialogOverviewExampleDialog {
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: DialogData, private DialogOverviewExample : DialogOverviewExample) {}
onNoClick(): void {
this.dialogRef.close();
}
onAddClick() :void{
this.DialogOverviewExample.LoadingCondition = true;
//makes a call to my service
//I want to start loading here
//but does not work
this.dialogRef.close();
}
}
dialog-overview-example-dialog.html
<h1 mat-dialog-title>Stuff to add</h1>
<div mat-dialog-content>
<p>add what?</p>
<mat-form-field>
<input matInput [(ngModel)]="data.animal">
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">No Click</button>
<button mat-button (click)="onAddClick()" cdkFocusInitial>add</button>
</div>
TLDR; When I press 'onAddClick()' the the loading bar does not show