NullInjectorError:没有为FaConfig提供程序

使用npm像提到的in github

angular-fontawesome 安装到angular应用中

在开发模式下工作正常。但是在生产版本中出现了错误。

当然,最初的错误是

NullInjectorError: StaticInjectorError(Do)[qm -> t]: StaticInjectorError(Platform: core)[qm -> t]: NullInjectorError: No provider for t!

必须将 angular.json 中的设置更改为

"optimization": false,...
"buildOptimizer": true,

找出实际错误

NullInjectorError: StaticInjectorError(AppModule)[FaIconComponent -> FaConfig]: StaticInjectorError(Platform: core)[FaIconComponent -> FaConfig]: NullInjectorError: No provider for FaConfig!

我该如何解决。

该模块具有

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';

已添加到导入

  @NgModule({
  declarations: [...],imports: [
    ...
    FontAwesomeModule
  ],

组件具有

import { faEllipsisV,... } from '@fortawesome/free-solid-svg-icons';

就像在指南中提到的那样。

这里是依赖项

  "dependencies": {
    "@angular/animations": "~8.2.11","@angular/cdk": "~8.2.3","@angular/common": "~8.2.11","@angular/compiler": "~8.2.11","@angular/core": "~8.2.11","@angular/forms": "~8.2.11","@angular/material": "^8.2.3","@angular/platform-browser": "~8.2.11","@angular/platform-browser-dynamic": "~8.2.11","@angular/router": "~8.2.11","@fortawesome/angular-fontawesome": "^0.6.0-alpha.0","@fortawesome/fontawesome-svg-core": "^1.2.25","@fortawesome/free-solid-svg-icons": "^5.11.2","bootstrap": "^4.3.1","classlist.js": "^1.1.20150312","hammerjs": "^2.0.8","ngx-bootstrap": "^5.2.0","ngx-cookie-service": "^2.2.0","ngx-webstorage-service": "^4.1.0","rxjs": "~6.4.0","tslib": "^1.10.0","web-animations-js": "^2.3.2","zone.js": "~0.9.1"
  }

Angular版本8.3.12.

WOAI88521 回答:NullInjectorError:没有为FaConfig提供程序

此错误是由于版本更新引起的,因为此问题在0.6.0-alpha.0仍然存在,请降级您的有角度字体真棒库。

例如,通过指定正确的版本来使用此命令:

npm我@ fortawesome / angular-fontawesome @ 0.5.0

Ps:直到angular8都可以使用,因为我没有在angular8 +上尝试过

,

降级到0.5.0对我有用。

,

您需要导入fortawesome库,然后在其中添加实体图标。 https://www.npmjs.com/package/@fortawesome/fontawesome-svg-core

import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { fas,faEllipsisV } from '@fortawesome/free-solid-svg-icons';

library.add(fas,faEllipsisV);
,

这是最新版本0.6.0-alpha.0中的一个问题,当您不指定版本时,它可能会自动安装。

https://github.com/FortAwesome/angular-fontawesome/issues/210

您可以降级到0.5.0版本来解决此AOT构建错误:

npm i @fortawesome/angular-fontawesome@0.5.0
本文链接:https://www.f2er.com/3052139.html

大家都在问