我想在我的Angular项目中使用fontawesome。我想尝试FortAwesome/angular-fontawesome,但如果我尝试使用图标,我会在浏览器控制台中收到错误:
ERROR TypeError: Cannot read property 'html' of undefined
at FaIconComponent.ngOnChanges (webpack-internal:///../../../../@fortawesome/angular-fontawesome/@fortawesome/angular-fontawesome.es5.js:112)
at checkAndUpdateDirectiveInline (webpack-internal:///../../../core/esm5/core.js:12576)
at checkAndUpdateNodeInline (webpack-internal:///../../../core/esm5/core.js:14104)
at checkAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:14047)
at debugCheckAndUpdateNode (webpack-internal:///../../../core/esm5/core.js:14940)
at debugCheckDirectivesFn (webpack-internal:///../../../core/esm5/core.js:14881)
at Object.eval [as updateDirectives] (ng:///AppModule/AppComponent.ngfactory.js:154)
at Object.debugUpdateDirectives [as updateDirectives] (webpack-internal:///../../../core/esm5/core.js:14866)
at checkAndUpdateView (webpack-internal:///../../../core/esm5/core.js:14013)
at callViewAction (webpack-internal:///../../../core/esm5/core.js:14364)
我安装了@fortawesome/angular-fontawesome
和两个依赖项(@fortawesome/fontawesome-free-solid
和@fortawesome/fontawesome-free-brands
)和npm
我将其导入app.module.ts
,并将其添加到imports
:
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
安装过程中是否遗漏了什么?当我使用ng serve --open
启动应用程序时终端没有错误,我只在浏览器控制台中收到错误。
答案 0 :(得分:2)
我遇到了同样的错误,只是意识到我的模板值与组件名称不匹配。
<button type="button" class="btn btn-default">
<fa-icon [icon]="caretLeft"></fa-icon>
</button>
在我的组件中,我有
private faCaretLeft = faCaretLeft;
这是一个新手错误,源于一些重命名,我试图解决以前的错误。当我将图标绑定更改为正确的名称时,错误已解决。
<button type="button" class="btn btn-default">
<fa-icon [icon]="faCaretLeft"></fa-icon>
</button>