错误TypeError:无法读取属性' html' undefined(angular-fontawesome)

时间:2018-02-09 00:33:02

标签: javascript angular

我想在我的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启动应用程序时终端没有错误,我只在浏览器控制台中收到错误。

1 个答案:

答案 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>