ionic4自定义组件报错’ion-‘ is not a known element:
项目要把顶部返回按钮抽成单个组件,于是使用ionic g component xx/xx/back 生成了组件文件
back.component.html中使用了ion-buttons
然后在公共的sharedModule里引入了这个组件:
@NgModule({
declarations: [BackComponent],
imports: [CommonModule],
exports: [BackComponent],
})
export class SharedModule {}
结果一直报错:
Uncaught Error: Template parse errors:
'ion-back-button' is not a known element:
1. If 'ion-back-button' is an Angular component, then verify that it is part of this module.
2. If 'ion-back-button' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
[ERROR ->]
......
这是因为没引入IonicModule引起的,在sharedModule里引入就好了:
@NgModule({
declarations: [BackComponent],
imports: [CommonModule, IonicModule],
exports: [BackComponent],
})
export class SharedModule {}