Issue
In angular2 I have a pipe that is used in two components and would like to know how to share it globally
I'm using angular2 and typescript.
My filter is called filterJobs pipe.
Where is best to inject filterJobs pipe so that it's available to both components from a global location?
This is my current attempt at making an ngModule for the filter to share it:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { JobsFilter } from './jobsFilter';
@NgModule({
imports: [CommonModule],
declarations: [JobsFilter],
exports: [JobsFilter],
providers: []
})
export class JobsFilterModule { }
Then do I simply inject "JobsFilterModule" into the component that needs it? If yes then does this go into the import section?
Solution
Create a module @NgModule()class MyPipeModule {} where you put the pipe in declarations: [] and exports: [], then add MyPipeModule to imports: [] of very module where you want to use it.
This will make the pipe and other components, and directives added to exports: [] available to all components in your current module.
Answered By - Günter Zöchbauer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.