cha1nsaw
cha1nsaw

Reputation: 67

Not able to decalre the custom pipes in angular

shortend.pipe.ts created inside app folder

import { PipeTransform } from "@angular/core";

export class ShortendPipe implements PipeTransform {

    transform(value: any, ...args: any[]) {
        return value.substr(0, 10)
    }
}

while declaring the custom pipe inside the app.module.ts inside the declaration array it is giving array saying only components, directives or pipes are allowed and shortendPipe is none.

How to resolve the above issue? Thanks in advance

Upvotes: 0

Views: 58

Answers (1)

Enak
Enak

Reputation: 596

My comment as full answer:

You are missing the @Pipe annotation. Add the import for Pipe and add the annotation for it. e.g.:

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

@Pipe({name: 'shortend'})
export class ShortendPipe implements PipeTransform {

    transform(value: any, ...args: any[]) {
        return value.substr(0, 10)
    }
}

See Usage notes here: https://angular.io/api/core/PipeTransform

Upvotes: 1

Related Questions