Hello, I'm creating a project in Angular2 + Webpack and in this project I use the @angular/material
as the design library. So that I can create my own icons using SVG, I'm extending the component MatIcon
as it says in the documentation , and I'm saving my SVG to a handy application directory. The project structure looks like this:
- src
| - app
| my-icon.component.ts
| - assets
| - svg
| - facebook.svg
| - google.svg
| - twitter.svg
My component is as follows:
import { Component, Input } from "@angular/core";
import { DomSanitizer } from "@angular/platform-browser";
import { MatIconRegistry } from "@angular/material";
export const icons = ["google", "facebook", "twitter"];
@Component({
selector: "my-icon",
template: '<mat-icon [svgIcon]="icon"></mat-icon>'
})
export class MyIcon {
@Input() icon: string;
constructor(i: MatIconRegistry, s: DomSanitizer) {
for (let icon of icons)
i.addSvgIcon(icon, s.bypassSecurityTrustResourceUrl('assets/svg/${icon}.svg'));
}
}
My problem is that every time I create a new SVG that would be an icon I'm forced to come in my component and update my constant icons
with the SVG name.
Is there any way I can read all the files in the "assets / svg" folder and insert it in my constant mine? I even saw that it is possible to do this using the fs of the NodeJS as can be seen