Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mat-spinner is not showing while loading angular app-root in index.html

Requirement:

I want to show a <mat-spinner> while loading the <app-root> in Angular

Code tried:

index.html:

<body>
  <app-root>Loading ...
    <mat-spinner></mat-spinner>
  </app-root>
</body>

app.module.ts:

import {
   ...,
   MatProgressSpinnerModule,
   ... }from '@angular/material';

@NgModule({
  declarations: [
  ...
  ],
  imports: [
    ...,
    MatProgressSpinnerModule,
    ...
  ],
  ...
})

Version info:

Angular CLI: 6.2.2
Node: 10.5.0
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Result:

Its showing Loading ... but not showing <mat-spinner> , tried spinner alone as well as with "Loading ..." text as given above, but the result is same - <mat-spinner> doesn't show.

Am I missing anything here ?

like image 523
Jithin Scaria Avatar asked Sep 02 '25 08:09

Jithin Scaria


1 Answers

While application initially loads angular hasn't loaded the App module yet so it doesn't know what mat-spinner is at that point.

You would need to use something that's is not angular if you want to show any thing before the modules are loaded. Your best shot would be a gif-spinner

like image 170
Tauqeer H. Avatar answered Sep 04 '25 23:09

Tauqeer H.