自定义组件 IONIC 4

Tia*_*ira 2 javascript components typescript ionic-framework angular

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

在此处输入图片说明

在此处输入图片说明

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

Jay*_*way 6

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

共享模块.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 {}
Run Code Online (Sandbox Code Playgroud)

然后对于 home.module.ts

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