无法绑定到 'icon',因为它不是 'fa-icon' 的已知 属性
Can't bind to 'icon' since it isn't a known property of 'fa-icon'
我在我的项目中使用 ngx-share
's Share Button Directive。但是,我似乎无法使用图标。如果我尝试使用这样的图标:
<button mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
<fa-icon [icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
我得到的是以下错误:
Uncaught Error: Template parse errors:
Can't bind to 'icon' since it isn't a known property of 'fa-icon'.
1. If 'fa-icon' is an Angular component and it has 'icon' input, then verify that it is part of this module.
2. If 'fa-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("on mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
<fa-icon [ERROR ->][icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
"): ng:///AppModule/GroupComponent.html@49:13
'fa-icon' is not a known element:
1. If 'fa-icon' is an Angular component, then verify that it is part of this module.
2. If 'fa-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<button mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
[ERROR ->]<fa-icon [icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
"): ng:///AppModule/GroupComponent.html@49:4
at syntaxError (compiler.js:486)
at TemplateParser.parse (compiler.js:24674)
at JitCompiler._parseTemplate (compiler.js:34629)
at JitCompiler._compileTemplate (compiler.js:34604)
at eval (compiler.js:34505)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:34505)
at eval (compiler.js:34375)
at Object.then (compiler.js:475)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
我该如何解决这个问题?
我将 ShareModule
添加到导入列表中:
@NgModule({
imports: [
//..
ShareModule.forRoot()
]
})
我的组件还根据需要注入 ShareButtons
对象:
export class GroupComponent {
constructor(public share: ShareButtons) {
}
}
您需要在使用这些分享按钮的模块中导入 ShareButtonsModule
。
import { ShareButtonsModule } from '@ngx-share/buttons';
@NgModule({
imports: [
ShareButtonsModule.forRoot()
]
})
编辑
您还可以导入已经导出 FontAwesomeModule
的
ShareButtonModule
。
原回答
假设您已经安装了 font awesome npm 包,您需要将 FontAwesomeModule
添加到模块的导入中
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@NgModule({
//...
imports: [
//...
FontAwesomeModule
],
})
export class AppModule { }
在此处查看示例
https://www.npmjs.com/package/@fortawesome/angular-fontawesome
我在我的项目中使用 ngx-share
's Share Button Directive。但是,我似乎无法使用图标。如果我尝试使用这样的图标:
<button mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
<fa-icon [icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
我得到的是以下错误:
Uncaught Error: Template parse errors:
Can't bind to 'icon' since it isn't a known property of 'fa-icon'.
1. If 'fa-icon' is an Angular component and it has 'icon' input, then verify that it is part of this module.
2. If 'fa-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("on mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
<fa-icon [ERROR ->][icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
"): ng:///AppModule/GroupComponent.html@49:13
'fa-icon' is not a known element:
1. If 'fa-icon' is an Angular component, then verify that it is part of this module.
2. If 'fa-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
<button mat-fab shareButton="telegram" [style.backgroundColor]="share.prop.telegram.color">
[ERROR ->]<fa-icon [icon]="share.prop.telegram.icon" size="lg"></fa-icon>
</button>
"): ng:///AppModule/GroupComponent.html@49:4
at syntaxError (compiler.js:486)
at TemplateParser.parse (compiler.js:24674)
at JitCompiler._parseTemplate (compiler.js:34629)
at JitCompiler._compileTemplate (compiler.js:34604)
at eval (compiler.js:34505)
at Set.forEach (<anonymous>)
at JitCompiler._compileComponents (compiler.js:34505)
at eval (compiler.js:34375)
at Object.then (compiler.js:475)
at JitCompiler._compileModuleAndComponents (compiler.js:34374)
我该如何解决这个问题?
我将 ShareModule
添加到导入列表中:
@NgModule({
imports: [
//..
ShareModule.forRoot()
]
})
我的组件还根据需要注入 ShareButtons
对象:
export class GroupComponent {
constructor(public share: ShareButtons) {
}
}
您需要在使用这些分享按钮的模块中导入 ShareButtonsModule
。
import { ShareButtonsModule } from '@ngx-share/buttons';
@NgModule({
imports: [
ShareButtonsModule.forRoot()
]
})
编辑
您还可以导入已经导出 FontAwesomeModule
的
ShareButtonModule
。
原回答
假设您已经安装了 font awesome npm 包,您需要将 FontAwesomeModule
添加到模块的导入中
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@NgModule({
//...
imports: [
//...
FontAwesomeModule
],
})
export class AppModule { }
在此处查看示例
https://www.npmjs.com/package/@fortawesome/angular-fontawesome