bug([Icon]): [SVG Icon not displaying]
Reproduction
https://stackblitz.com/angular/yjprlknbxmgk?file=src%2Fapp%2Ficon-svg-example.html
Steps to reproduce: Create a component and register an icon in MatIconRegistry:
import {Component, OnInit} from '@angular/core';
import {MatIconRegistry} from '@angular/material';
import {DomSanitizer} from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
constructor(private _matIconRegistry: MatIconRegistry, private _domSanitizer: DomSanitizer) {
iconRegistry.addSvgIcon(
'thumbs-up',
sanitizer.bypassSecurityTrustResourceUrl('assets/img/examples/thumbup-icon.svg'));
}
ngOnInit() {
}
}
<mat-icon svgIcon="thumbs-up" aria-hidden="false" aria-label="Example thumbs up SVG icon"></mat-icon>
Expected Behavior
SVG icon 'thumbs up' should be displayed
Actual Behavior
Console Error of Error: Error retrieving icon :thumbs-up! <svg> tag not found
Environment
- Angular: 7.0.2
- CDK/Material: 6.4.7
- Browser(s): chrome 83.0.4103.61
- Operating System: MacOS 10.14.6
I think this is just an issue with the stackblitz example, the same example on the material.angular.io docs site works fine: https://material.angular.io/components/icon/examples
forgive my ignorance, are those inline examples live? I'm getting a similar error on a local build as well and was just looking for a real example to compare to when I noticed it being broken on stackblitz.
Yes, that example is live. The reason the stackblitz one isn't working is because the url is not returning the svg asset, its returning an HTML document (probably the default thing stackblitz serves for invalid paths). I suggest using the Chrome DevTools Network tab to inspect the icon request and see what's actually being served in your app.
Duplicate of https://github.com/angular/components/issues/16484.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.