我是 Angular 的新手,所以请耐心等待。我正在尝试在我的项目中使用 FontAwesome。最初我通过 CDN 加载它,但我想正确使用它。所以我已经FontAwesomeModule
将WidgetModule
. 看起来像这样:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { WidgetRoutingModule } from './widget-routing.module';
import { SharedModule } from '@pyb-shared/shared.module';
import { WidgetComponent } from './widget.component';
import { ScenariosComponent } from './scenarios/scenarios.component';
import { QuestionsComponent } from './questions/questions.component';
import { AnswersComponent } from './answers/answers.component';
import { ResultsComponent } from './results/results.component';
import { AnswerButtonComponent } from './shared/answer-button/answer-button.component';
import { HeaderComponent } from './shared/header/header.component';
import { LoadingButtonComponent } from './shared/loading-button/loading-button.component';
import { MainProductComponent } from './shared/main-product/main-product.component';
import { MatchesComponent } from './shared/matches/matches.component';
import { ProductComponent } from './shared/product/product.component';
import { QuestionSplitComponent } from './shared/question-split/question-split.component';
import { AnswersService } from './answers/answers.service';
import { QuestionsService } from './questions/questions.service';
import { ResultsService } from './results/results.service';
import { ScenariosService } from './scenarios/scenarios.service';
import { AnswerMatchService } from './shared/answer-match.service';
import { DuplicateService } from './shared/duplicate.service';
import { FilterService } from './shared/filter.service';
import { FormulaService } from './shared/formula.service';
import { MatchesService } from './shared/matches.service';
import { PickService } from './shared/pick.service';
import { QuestionSplitService } from './shared/question-split/question-split.service';
import { StateService } from './shared/state.service';
import { WidgetService } from './widget.service';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faSquare, faCheckSquare } from '@fortawesome/pro-solid-svg-icons';
@NgModule({
imports: [
CommonModule,
WidgetRoutingModule,
SharedModule,
FontAwesomeModule
],
declarations: [
WidgetComponent,
ScenariosComponent,
QuestionsComponent,
AnswersComponent,
ResultsComponent,
AnswerButtonComponent,
HeaderComponent,
LoadingButtonComponent,
MainProductComponent,
MatchesComponent,
ProductComponent,
QuestionSplitComponent
],
providers: [
AnswersService,
QuestionsService,
ResultsService,
ScenariosService,
AnswerMatchService,
DuplicateService,
FilterService,
FormulaService,
MatchesService,
PickService,
QuestionSplitService,
StateService,
WidgetService
]
})
export class WidgetModule {
constructor() {
console.log('WidgetModule loaded.');
library.add(faSquare, faCheckSquare);
}
}
我想在我的组件上显示两个图标,因此您可以在上面的模块中看到我添加了faSquare和faCheckSquare。在我的组件(称为ScenariosComponent)中,我只有这个跨度:
<span class="fas fa-square"></span>
从我上面提供的链接,看看这个:
https://github.com/FortAwesome/angular-fontawesome
看起来它应该工作。我导入了FontAwesomeModule,ScenariosComponent将WidgetModule作为其父模块,所以它应该可以正常工作。根据这条线:
添加到库中的图标将可供其父模块也导入 FontAwesomeModule 的任何其他组件使用。
而且我确实在我的模块中设置了我的库。至少在我的理解中,哪个应该在该模块中工作。
我这样做对吗?