Tuesday, May 23, 2017

When adding a pipe at the one module that wraps everything, the pipe goes in the declarations property at the @NgModule decorator in Angular 2.

When an app has many modules for many nested russian dolls or functionality. The pipe needs its own module like so:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { SimpleDatePipe } from "./simple-date.pipe";
@NgModule({
   declarations: [SimpleDatePipe],
   exports: [SimpleDatePipe],
   imports: [CommonModule]
})
export default class SimpleDateModule {
}

 
 

For this to work, SimpleDatePipe must become an item in the array for the "imports" property at the @NgModule decorator for the module wrapping the component that uses the template where the pipe is utilized.

No comments:

Post a Comment