问题
I'm using Angular 6 angular-starter and fontawesome, followed here on how to install fa to ng.
In my .ts looks like this:
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();
}
Then in .html:
<fa-icon [icon]="['fab', 'instagram']"></fa-icon>
It works perfectly fine except for free brands, @fortawesome/free-brands-svg-icons
. On build (npm start) it produces error/warning 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'.
on the 92% build but actually the build appears to be successful and the instagram icon shows up but I'm bothered because a red line below the code appears.
Can someone figure it out?
My 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",
回答1:
I'll mention a case with regular icons. Hope a similar approach will help you. You can just import the icon and then typecast it from IconDefinitionOrPack to IconDefinition while adding it to the library in your module constructor.
import { faTimesCircle, faCheckCircle } from '@fortawesome/free-regular-svg-icons';
Then while adding it in library typecast it
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>
来源:https://stackoverflow.com/questions/53067036/argument-of-type-icondefinition-is-not-assignable-to-parameter-of-type-iconde