I’m working on an Angular 10 application and using Angular Material Icons. I’m looking for a way to dynamically display a dropdown list containing all the available Material Icons.
I’ve attempted to retrieve the list programmatically using MatIconRegistry, but so far, the icons array remains empty. Here’s the relevant code snippet:
this.matIconRegistry['_iconSetConfigs'].forEach((config: any) => {
if (config.names) {
config.names.forEach((name: string) => {
const sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(config.url);
ics.push(name);
});
}
});
Is there a reliable approach to fetch the list of Material Icons and display them in a dropdown in Angular 10?
Any insights or alternative solutions would be highly appreciated.
Thank you!
2
Answers
if you want to display the icon from the material, you can do it like this
You may not want to display all the material icons in a dropdown as there are more than 900. Angular doesn’t provide an API to get the list programmatically but here are the codes for them.
Note that lately they went for the font route:
Ideally you would have a list of the desired icons and use the approach suggested by Kenedy.