简体   繁体   English

如何使用 Angular 材料(如 Angular.io/resources 网站)插入社交图标?

[英]How to insert social icons using Angular Material like the Angular.io/resources site?

I've installed Angular Material and have been able to use the icons by simply importing the material module and using the mat-icon element:我已经安装了 Angular Material 并且能够通过简单地导入材料模块并使用 mat-icon 元素来使用图标:

<mat-icon>mood</mat-icon>

However I would like to use the social icons like the one on the angular.io/resources site.但是,我想使用angular.io/resources网站上的社交图标。

When I inspect the element it seems they are drawing an svg using the path element's d attribute value, however I'm not sure how the Angular community usually gets these data values, is there a standard resource developers use rather than the tedious task of drawing it out themselves?当我检查元素时,似乎他们正在使用路径元素的 d 属性值绘制 svg,但是我不确定 Angular 社区通常如何获取这些数据值,是否有标准资源开发人员使用而不是繁琐的绘图任务自己出吗? At the moment I just resort to copying and pasting the d value lol, however I'm wondering if there's a more practical approach developers use.目前我只是求助于复制和粘贴 d 值大声笑,但是我想知道是否有开发人员使用的更实用的方法。

在此处输入图像描述

Create a svg file (inkscape, illustrator) or download it and register it like this in a service:创建一个 svg 文件(inkscape,illustrator)或下载它并像这样在服务中注册它:

@Injectable({providedIn: 'root'})
export class MaterialIconsService {
    constructor(private iconRegistry: MatIconRegistry,
                private sanitizer: DomSanitizer) {
        this.iconRegistry.addSvgIcon('my-icon', this.sanitizer.bypassSecurityTrustResourceUrl('assets/path/my-icon.svg');
    }
}

Then you can use in it in your html然后你可以在你的 html 中使用它

<mat-icon svgIcon="my-icon"></mat-icon>

More information here:https://material.angular.io/components/icon/api#MatIconRegistry更多信息在这里:https://material.angular.io/components/icon/api#MatIconRegistry

All the Material icons are open source.所有 Material 图标都是开源的。

  1. Go to the Material Icons site. Go 到 Material Icons 网站。
  2. Click on an icon.单击一个图标。
  3. Click on the SVG download link at the bottom left of the page.点击页面左下方的SVG下载链接。

Alternatively click on the link to "git repository".或者单击“git 存储库”的链接。 Where you can browse the source repo and download some or all of the icons.您可以在其中浏览源代码库并下载部分或全部图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM