3
votes

This question is very similar to How can we use Provider in Pipe files while using Deep Linking and Lazy Loading Ionic 3? but in this question, we don't use Provider.

I have a 2 Lazy Loading Pages Page1 and Page2 and HomePage as a root page. In addition, MyPipe file is the Pipe file. as given below. I want to use this Pipe file in LAzy Loading Files Page1 and Page2 and HomePage

Case 1: If I add Pipe file only on app.module

then below error occurs

Runtime Error Uncaught (in promise): Error: Template parse errors: The pipe 'myPipe' could not be found (" {{[ERROR ->]'test1' | myPipe}} "): ng:///Page1PageModule/Page1Page.html@16:2 Error: Template parse errors: The pipe 'myPipe' could not be found (" {{[ERROR ->]'test1' | myPipe}} "):

Case 2: If I import Pipe file to Page1Module and Page2Module

then below error occurs

Runtime Error Uncaught (in promise): Error: Type MyPipe is part of the declarations of 2 modules: Page1PageModule and Page2PageModule! Please consider moving MyPipe to a higher module that imports Page1PageModule and Page2PageModule. You can also create a new NgModule that exports and includes MyPipe then import that NgModule in Page1PageModule and Page2PageModule. Error: Type MyPipe is part of the declarations of 2 modules: Page1PageModule and Page2PageModule! Please consider moving MyPipe to a higher module that imports Page1PageModule and Page2PageModule. You can also create a new NgModule that exports and includes MyPipe then import that NgModule in Page1PageModule and Page2PageModule.

Thanks for your recommendations.

1

1 Answers

5
votes

It is very simple. This is my workflow.

  1. I create pipe using this CLI: ionic generate pipe MyFilter

  2. Then it'll create pipes.module.ts automatically.

  3. After that, I just import it into my lazy loaded page's module as below.

member.module.ts

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { MemberPage } from './member';
import { PipesModule } from '../../pipes/pipes.module';

@NgModule({
  declarations: [
    MemberPage,
  ],
  imports: [
    IonicPageModule.forChild(MemberPage),
    PipesModule <-- here
  ],
})
export class MemberPageModule { }
  1. That is it. No errors and pipe is working perfectly too :)