1

I have created a custom pipe to use in my Angular 2 app. My view code using the pipe looks like this:

<div class="search-item-name">{{result.name}} <span class="search-context">{{result.type | contextualize}}</span></div> 

The pipe file itself looks like this:

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

@Pipe({name: 'contextualize'}) export class ContextPipe implements PipeTransform { transform(value: string) { // Logic here... } } } 

However, after trying to use it in my component view, I am getting this error:

Template parse errors: The pipe 'contextualize' could not be found

I'm unclear why this is the case. I have put the pipe in a shared module:

import { ContextPipe } from './context.pipe'; import { CapitalizePipe } from './capitalize.pipe'; import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { AbbreviatePipe } from './abbreviate.pipe'; @NgModule({ imports: [ CommonModule ], declarations: [ CapitalizePipe, AbbreviatePipe, ContextPipe ], exports: [ CapitalizePipe, AbbreviatePipe, ContextPipe ], }) export class SharedModule { } 

And then, in both the root ngModule and in the component I'm trying to use this pipe in, I have imported that SharedModule. But still the error appears. Is there something I'm overlooking here?

1
  • are you importing shared to the module you are trying to use correctly? Commented Apr 6, 2017 at 21:24

1 Answer 1

1

A this to your pipe code:

constructor() { } 

Like this:

@Pipe({name: 'contextualize'}) export class ContextPipe implements PipeTransform { constructor() { } transform(value: string) { // Logic here... } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.