Skip to content

[mat-icon] svgIcon renders the same icon for multiple resources #14959

@mrkpks

Description

@mrkpks

What is the expected behavior?

Have different icons rendered for each with different svgIcon value

What is the current behavior?

All icons are rendered as my_icon1.svg.

If I change order in html file f.e.:

<mat-icon svgIcon="my_icon2"></mat-icon>
<mat-icon svgIcon="my_icon1"></mat-icon>
<mat-icon svgIcon="my_icon3"></mat-icon>

-> all icons are rendered as my_icon2.svg, so it seems that it takes just the first svgIcon resource and renders it for all components in current view (even for nested components).

What are the steps to reproduce?

app.component.ts


import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
...
constructor(
    private readonly matIconRegistry: MatIconRegistry,
    private readonly sanitizer: DomSanitizer,
  ) {
    this.matIconRegistry.addSvgIcon('my_icon1', this.sanitizer.bypassSecurityTrustResourceUrl('assets/icons/my_icon1.svg'));
    this.matIconRegistry.addSvgIcon('my_icon2', this.sanitizer.bypassSecurityTrustResourceUrl('assets/icons/my_icon2.svg'));
    this.matIconRegistry.addSvgIcon('my_icon3', this.sanitizer.bypassSecurityTrustResourceUrl('assets/icons/my_icon3.svg'));
}
...

app.component.html

<mat-icon svgIcon="my_icon1"></mat-icon>
<mat-icon svgIcon="my_icon2"></mat-icon>
<mat-icon svgIcon="my_icon3"></mat-icon>

app.module.ts

import { HttpClientModule } from '@angular/common/http';
import { MatIconModule } from '@angular/material';

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular CLI: 7.2.3
Node: 10.14.1
OS: win32 x64
Angular: 7.2.2

Is there anything else we should know?

I'm using Ionic 4.9.0 for native mobile app development.

On all my previous projects this worked fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cannot reproduceThe team is unable to reproduce this issue with the information providedneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions