Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Angular loading icon from material Registery is not preloaded

I have registered some svg's in app.component

public static MAT_ICONS_TO_REGISTOR: { name: string, url: string }[] = [
    {name: 'broom', url: '../assets/imgs/broom.svg'},
    {name: 'sources-icon', url: '../assets/imgs/camera_in.svg'}
 ];  



AppComponent.MAT_ICONS_TO_REGISTOR.forEach(icon => {
      this.matIconRegistry.addSvgIcon(icon.name,
        this.domSanitizer.bypassSecurityTrustResourceUrl(icon.url));
    });

But its not loaded on component init when *ngIf exists, ex:

  <div *ngIf="!isApproval">
            <mat-icon  svgIcon="broom"
                      (click)="onResubmitAction()">
            </mat-icon>
</div> 

In this case when the condition becomes true a get request will be sent to get the icon from assets ('http://localhost:4200/assets/imgs/broom.svg') but it should load it on component init.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When using *ngIf, the element will not be rendered until the condition inside is true. It seems like mat-icon does not start a request to load a new icon until rendered, so in order to load an icon you need to render mat-icon. If you want your element to be not visible but still rendered, you can use the hidden attribute:

<div [hidden]="isApproval">
  <mat-icon svgIcon="broom"
            (click)="onResubmitAction()">
  </mat-icon>
</div> 

hidden does not work when the display CSS property of the element to hide is overwritten at some point. So it is safer to add the following global style:

[hidden] {
  display: none !important;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda