[英]Angular Nebular theme using FontAwesome icon pack
The stack: Angular 9.1.7, Nebular 5.0.0, FontAwesome 5.13堆栈:Angular 9.1.7,Nebular 5.0.0,FontAwesome 5.13
I want to change the default icon set (EvaIcons) used by Nebular to FontAwesome using this guideline:我想使用以下指南将 Nebular 使用的默认图标集 (EvaIcons) 更改为 FontAwesome:
https://akveo.github.io/nebular/docs/guides/register-icon-pack#register-icon-pack https://akveo.github.io/nebular/docs/guides/register-icon-pack#register-icon-pack
Unfortunately the icons are not getting displayed.不幸的是,图标没有显示出来。 I'm close because the Nebular EvaIcons are no longer displayed.我很接近,因为星云 EvaIcon 不再显示。 From the DeveloperTools, i can see nb-icon
using fa-user
, but nothing is displayed.从 DeveloperTools 中,我可以看到nb-icon
使用fa-user
,但没有显示任何内容。
You didn't provide what you have installed or configured.您没有提供已安装或配置的内容。
But here comes my answer anyways... I have managed load FontAwesome into my Nebular app.但无论如何,我的答案来了……我已经将 FontAwesome 加载到我的 Nebular 应用程序中。 That said, not replacing EvaIcons but adding them additionally to Eva.也就是说,不是替换 EvaIcons,而是将它们另外添加到 Eva。
In Code:在代码中:
1. npm install --save @fortawesome/fontawesome-free
2. "styles": [..., "node_modules/@fortawesome/fontawesome-free/css/all.css", ...],
"scripts": [..., "node_modules/@fortawesome/fontawesome-free/js/all.js", ...]
3. import { NbIconLibraries } from '@nebular/theme';
@Component({
selector: 'ngx-app',
template: '<router-outlet></router-outlet>',
})
export class AppComponent implements OnInit {
constructor(private iconLibraries: NbIconLibraries) {
this.iconLibraries.registerFontPack('fas', { packClass: 'fas', iconClassPrefix: 'fa' });
this.iconLibraries.registerFontPack('far', { packClass: 'far', iconClassPrefix: 'fa' });
this.iconLibraries.registerFontPack('fab', { packClass: 'fab', iconClassPrefix: 'fa' });
this.iconLibraries.setDefaultPack('far');
...
4. <nb-icon icon="arrow-right" pack="fas"></nb-icon>
(Maybe there is a better way of doing this, maybe loading the js isn't required idk...)
This way you may use either Eva or FontAwesome Icons, or from whatever registered pack.这样您就可以使用 Eva 或 FontAwesome 图标,或任何注册包。
Eva: <nb-icon icon="SOME_ICON"> </nb-icon>
FontAwesome: <nb-icon icon="SOME_ICON" pack="fas/far/fab/fal/fad"></nb-icon>
Use the below method,使用下面的方法,
npm install --save @fortawesome/fontawesome-free
"styles": [
"node_modules/@fortawesome/fontawesome-free/css/all.css",
],
import { NbIconModule } from '@nebular/theme';
imports: [
NbIconModule,
],
constructor(private iconLibraries: NbIconLibraries) {
this.iconLibraries.registerFontPack('font-awesome', { packClass: 'fab', iconClassPrefix: 'fa' });
}
<nb-icon icon="instagram" pack="font-awesome"></nb-icon>
I hope it will work我希望它会工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.