简体   繁体   English

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

[英]Unable to share component between two pages angular ionic 3

I want to share component between two pages in ionic 3. 我想在Ionic 3的两个页面之间共享组件。

I have common component SearchInputComponent added in component folder. 我在组件文件夹中添加了通用组件SearchInputComponent

When i try to add, i was getting this error SearchInputComponent is part of the declarations of 2 modules 当我尝试添加时,出现此错误SearchInputComponent是2个模块的声明的一部分

After searching a bit on net i found a way ie create new sharedModule inside it keep common components. 在网上搜索了一下之后,我找到了一种方法,即在其中创建新的sharedModule,以保留通用组件。

So created SharedModule.module.ts in component folder. 因此在组件文件夹中创建了SharedModule.module.ts

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 {}

I want to use my SearchInputComponent in myPage1 and myPage2, 我想用我的SearchInputComponent在myPage1和myPage2,

so inside 所以里面

myPage1.module.ts myPage1.module.ts

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

myPage2.module.ts myPage2.module.ts

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

but it is not working, showing some weird Error: Template parse errors:.... 但它不起作用,显示一些奇怪的Error: Template parse errors:....

Can any one help me to find my mistake? 谁能帮我发现我的错误?

Thank you in advance! 先感谢您!

Could you please write all the error log? 您能写所有错误日志吗? It seems that you have exported and imported right the module. 看来您已经正确导出和导入了模块。 But maybe there is an error with the template. 但是,模板可能有错误。

For discarding template errors, try to comment all the logic on your 'SearchInputComponent'. 要丢弃模板错误,请尝试注释“ SearchInputComponent”上的所有逻辑。

I found the solution, It might help someone 我找到了解决方案,它可能会帮助某人

SharedModule.module.ts SharedModule.module.ts

I added imports: [IonicPageModule.forChild(SearchInputComponent)], and it got worked. 我添加了imports: [IonicPageModule.forChild(SearchInputComponent)],它开始起作用。

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

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