Elikos
Elikos

Reputation: 103

Angular 2 using custom pipe

I created a new pipe:

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'reverse'
})
export class ReversePipe {
  transform(arr) {
    var copy = arr.slice();
    return copy.reverse();
  }
}

Imported it in my component:

import { ReversePipe } from '../reverse.pipe';

Also here:

pipes: [ReversePipe]

but when I run my app I get

The pipe 'reverse' could not be found

What have I missed?

Upvotes: 0

Views: 1273

Answers (1)

silentsod
silentsod

Reputation: 8335

In the module that you intend to use the pipe

import { ReversePipe } from '../reverse.pipe';

And then in the declarations

NgModule({
 declarations: [
        <...>,
        ReversePipe
    ]

This makes the name available for template compilation.

Upvotes: 2

Related Questions