I have an array of objects that has the following structure:
import icon1 from '!!raw-loader!../../../icon1.svg';
import icon2 from '!!raw-loader!../../../icon2.svg';
import icon3 from '!!raw-loader!../../../icon3.svg';
import icon4 from '!!raw-loader!../../../icon4.svg';
import icon5 from '!!raw-loader!../../../icon5.svg';
export const CustomIcons = [
{
home: 'icon1',
homeIcon: (icon)
},
{
series: 'icon2',
seriesIcon: (icon2)
},
{
explorer: 'icon3',
explorerIcon: (icon3)
},
...
];
Within the module's constructor, I aim to utilize the values in this way:
export class IconRegistryModule {
constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
CustomIcons.forEach(icon => {
iconRegistry.addSvgIconLiteral(Object.keys(icon)[0], sanitizer.bypassSecurityTrustHtml(Object.keys(icon)[1]));
});
}
}
Therefore, the addSvgIconLiteral method should be implemented as follows for the initial iteration of the forEach loop:
iconRegistry.addSvgIconLiteral('the value of the key home', sanitizer.bypassSecurityTrustHtml('the value of the key homeIcon');