app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
isTaskRunning:boolean = false;
message:string = "The task is not run yet."
runTask(){
this.isTaskRunning = true;
this.message = "Task is running now."
// Do the task here
this.delay(15).then(()=>{
this.isTaskRunning = false;
this.message = "Task is finished."
});
}
delay(seconds:number) {
return new Promise(
resolve => setTimeout(resolve, seconds * 1000)
);
}
}
app.component.html
<h2 style="padding-top:25px; padding-bottom:25px;">
Angular Material - How to center Progress spinner
</h2>
<h4 style="margin-bottom:25px;">
{{message}}
</h4>
<button
mat-raised-button
color="secondary"
[disabled]="isTaskRunning"
style="margin-bottom:25px;"
(click)="runTask()">
Run Task
</button>
<mat-progress-spinner
color="warn"
mode="indeterminate"
style="margin:0 auto;"
*ngIf="isTaskRunning">
</mat-progress-spinner>
app.module.ts [import]
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'
import {MatButtonModule} from '@angular/material/button'
- angular material - How to change Progress spinner color
- angular material - How to use Card
- angular material - How to use Tabs
- angular material - How to use custom label in Tabs
- angular material - How to change Badge size
- angular material - How to use custom Badge size
- angular material - How to show custom color in Badge
- angular material - How to show Badge in a button
- angular material - How to show Badge with icon
- angular material - Badge position before & below after
- angular material - Open Accordion multiple panels at once
- angular material - How to disable a panel in Accordion
- angular material - How to hide Accordion panels toggle icon
- angular material - Determine an Expansion Panel is disabled or enabled
- angular material - How to toggle Expansion Panel expanded state