我在用着Angular 6 角度启动器 https://github.com/gdi2290/angular-starter和fontawesome,跟随here https://github.com/FortAwesome/angular-fontawesome关于如何安装 fa 到 ng。
在我的 .ts 中看起来像这样:
import { library, dom } from '@fortawesome/fontawesome-svg-core';
import { faInstagram } from '@fortawesome/free-brands-svg-icons/faInstagram';
import { faLink } from '@fortawesome/free-solid-svg-icons/faLink';
public ngOnInit() {
library.add(faInstagram);
library.add(faLink);
dom.watch();
}
然后在.html中:
<fa-icon [icon]="['fab', 'instagram']"></fa-icon>
除了免费品牌外,它工作得很好,@fortawesome/free-brands-svg-icons
。在构建(npm start)时它会产生错误/警告Argument of type 'IconDefinition' is not assignable to parameter of type 'IconDefinitionOrPack'. 'IconDefinition' is not assignable to type 'IconPack'. signature is missing in type 'IconDefinition'.
在 92% 的构建上,但实际上构建似乎是成功的,并且显示了 Instagram 图标,但我很烦恼,因为代码下方出现了一条红线。
有人能弄清楚吗?
我的package.json
"@fortawesome/angular-fontawesome": "^0.3.0",
"@fortawesome/fontawesome-svg-core": "^1.2.6",
"@fortawesome/free-brands-svg-icons": "^5.4.2",
"@fortawesome/free-solid-svg-icons": "^5.4.1",
我会提到一个带有常规图标的案例。希望类似的方法对您有所帮助。您只需导入图标,然后从图标定义或包 to 图标定义同时将其添加到模块构造函数中的库中。
import { faTimesCircle, faCheckCircle } from '@fortawesome/free-regular-svg-icons';
然后在将其添加到库中时对其进行类型转换
export class AppModule {
constructor() {
library.add(faTable);
library.add(faChartArea);
library.add(faTachometerAlt);
library.add(faTimesCircle as IconDefinition);
library.add(faCheckCircle as IconDefinition);
}
}
In HTML,
<div class="col-md-6">
<fa-icon [icon]="['far', 'check-circle']"></fa-icon>
<span>Tax Info</span>
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)