我使用npm像github上提到的那样,在angular应用程序中安装了angular-fontawesome。
在开发模式下运行良好。但是在生成的构建中出现错误。
当然初始错误是:
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。