Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

191
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!