无法在两页角离子3之间共享组件

时间:2018-11-28 07:26:31

标签: angular ionic-framework ionic3 angular2-template angular-components

我想在ionic 3的两个页面之间共享组件。

我在组件文件夹中添加了公共组件SearchInputComponent

当我尝试添加时,出现此错误 SearchInputComponent是2个模块的声明的一部分

在网上搜索了一下之后,我找到了一种方法,即在其中创建新的sharedModule,以保留通用组件。

因此在组件文件夹中创建了SharedModule.module.ts

SharedModule.module.ts

import { NgModule } from '@angular/core';
import { SearchInputComponent } from './search-input/search-input';

@NgModule({
    imports: [
     ],
    declarations: [
        SearchInputComponent
    ],
    exports: [
        SearchInputComponent
    ]
})

export class SharedModule {}

我想在myPage1和myPage2中使用我的SearchInputComponent

在里面

myPage1.module.ts

@NgModule({
  declarations: [
    myPage1
  ],
  imports: [
    IonicPageModule.forChild(myPage1),
    SharedModule
  ],
})
export class myPage1PageModule {}

myPage2.module.ts

@NgModule({
  declarations: [
    myPage2
  ],
  imports: [
    IonicPageModule.forChild(myPage2),
    SharedModule
  ],
})
export class myPage2PageModule {}

但是它不起作用,显示出一些奇怪的Error: Template parse errors:....

有人可以帮助我发现我的错误吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

能否请您写下所有错误日志? 看来您已经正确导出和导入了模块。但是模板可能有错误。

要丢弃模板错误,请尝试注释“ SearchInputComponent”上的所有逻辑。

答案 1 :(得分:0)

我找到了解决方案,它可能会对某人有所帮助

SharedModule.module.ts

我添加了 imports: [IonicPageModule.forChild(SearchInputComponent)],并成功了。

相关问题