定制组件IONIC 4

时间:2019-03-04 19:54:39

标签: javascript angular typescript ionic-framework components

我有一个离子应用程序,并为ion-navbar创建了一个自定义组件,但是如何在所有页面中使用该组件?如果我在所有页面上都声明他,则会出现此错误

enter image description here

enter image description here

如果您要https://github.com/tiagosilveiraa/PManager,这是我的Github

1 个答案:

答案 0 :(得分:2)

您可以创建一个共享模块,并将新共享模块作为需要标题的页面模块的导入:

shared.module.ts

import { NgModule } from '@angular/core';

import {CommonModule} from '@angular/common';
import {HeaderComponent} from './header/header.component';
import {IonicModule} from '@ionic/angular';

@NgModule({
    imports: [
        CommonModule,
        IonicModule
    ],
    declarations: [HeaderComponent],
    exports: [HeaderComponent]
})
export class SharedModule {}

然后输入home.module.ts

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    SharedModule,
    RouterModule.forChild(routes),  
  ],
  declarations: [HomePage]
})
export class HomePageModule {}