将Ionic页面添加到另一个Ionic页面 - Ionic 4

问题描述 投票:0回答:1

我有一个页面,我在Ionic 4应用程序中用作普通页面,但我还需要在应用程序的其他页面中重用它,以便停止重复代码。

我当前的方法是遵循正常指令所采用的方法,并将选择器添加到我希望将页面放入的页面中:

<app-child></app-child>

然后将子页面模块导入添加到父页面模块:

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    RouterModule.forChild(routes),
    ComponentsModule,
    ChildPageModule,
  ],
  declarations: [ParentPage]
})
export class ParentPageModule {}

但是我遇到了错误:

ChildPage is part of the declarations of 2 modules:

这当然是有道理的,因为它是一个主页面,现在是一个组件页面。

我尝试将导入移动到app模块,尝试将页面添加到父页面模块的声明中,但都无法解决问题。

关于如何在Ionic 4 / Angular 6中获取页面内页面的任何想法

angular ionic-framework ionic4
1个回答
0
投票

您应该为Childpage创建一个组件。

@Component({
  selector: 'app-childpage',
  templateUrl: './childpage.component.html'
})

export class ChildpageComponent {

}

然后创建一个components.module.ts并执行:

@NgModule({
  declarations: [
    ChildpageComponent
  ],
  imports: [
    ...
  ],
  exports: [
    ChildpageComponent
  ]
})
export class ComponentsModule {}

现在,您可以通过将<app-childpage></app-childpage>导入各自的模块,在其他页面中使用ComponentsModule选择器

© www.soinside.com 2019 - 2024. All rights reserved.