正如标题所说,我试图添加一些自定义的 svg 图标,这些图标从 https://simpleicons.org/ 下载。
我将我的图标放在应用程序的 assets 目录下名为 icons 的文件夹中。
然后,我注入了 MatIconRegistry 和 DomSanitizer 并像这样添加了 svg:
constructor(
private matIconRegistry: MatIconRegistry,
private domSanitizer: DomSanitizer
) {
this.matIconRegistry.addSvgIcon(
'facebook',
this.domSanitizer.bypassSecurityTrustResourceUrl(
'/assets/icons/facebook.svg'
)
);
this.matIconRegistry.addSvgIcon(
'google',
this.domSanitizer.bypassSecurityTrustResourceUrl(
'/assets/icons/google.svg'
)
);
this.matIconRegistry.addSvgIcon(
'twitter',
this.domSanitizer.bypassSecurityTrustResourceUrl(
'/assets/icons/twitter.svg'
)
);
}
我已在AppComponent中完成了这个操作。 在另一个组件中,我正在尝试使用这些图标。我已经做了这些:
<div class="form-group">
<button class="btn-block" type="button" color="secondary" mat-flat-button>
<mat-icon>twitter</mat-icon> Continue with
facebook
</button>
</div>
<div>
<button class="btn-block" type="button" color="secondary" mat-flat-button>
<mat-icon>twitter</mat-icon> Continue with
google
</button>
</div>
但是没有显示任何图标。 我想添加到AppComponent中将允许在任何地方使用图标。这是一个错误的假设吗?