Answers for "angular - declaring pipe in more than one component"

1

angular - declaring pipe in more than one component

1) Firstly, create pipes folder in src/app folder (in app folder).

2) Second, on cmd "ng generate pipe pipes/searchfilter" => this will generate two files in pipes.

3 Third, create file in pipes folder with name "pipes.module.ts" and write below code to => "pipes.module.ts"

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SearchfilterPipe } from './searchfilter.pipe';  //our pipe which we generate

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [SearchfilterPipe],
  exports: [SearchfilterPipe]
})
export class PipesModule { }
Now we have PipesModule we can generate more pipes and write them in pipesmodule. We will import only PipesModule instead of all pipes.

4) You do not have to import PipesModule in app.module.ts

5) Now go to page which you want to use pipe and open for example "anasayfa.module.ts" and import "PipesModule" and write it in @ngModel imports(it will be created automatically) Please be careful you will import PipesModule to something.MODULE.TS not something.page.ts
Posted by: Guest on July-12-2021

Code answers related to "angular - declaring pipe in more than one component"

Code answers related to "Javascript"

Browse Popular Code Answers by Language