繁体   English   中英

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

[英]Add an Ionic page into another Ionic Page - Ionic 4

我有一个页面,可以在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中获取页面内页面的任何想法

您应该为子页面创建一个组件。

@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导入各自的模块中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM