Angular 2 custom pipe not found

Cabe Skuriles

At first: Angular2: custom pipe could not be found this didn't help me in any case.. I have the following problem:

Pipe:

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

@Pipe({
    name: "ToNumberPipe"
})
export class ToNumberPipe extends DecimalPipe implements PipeTransform  {
    // this allows to pass strings in decimalpipes as well and do nothing if it NAN
    public transform(value: string, args: string): any {
        const retNumber = Number(value);
        if (isNaN(retNumber)) {
            return value;
        }
        return super.transform(value, args);
    }
}

App:module

@NgModule(
    {
        // all components, pipes and directive which are using this module
        declarations: [AppComponent, ... all Components go here],
        // All modules like forms or http
        imports: [...., MainPipeModule],
        // all services and other providers
        providers: [...all services go here],
        bootstrap: [AppComponent]
    }
)
export class AppModule {
}

Pipe Module

import { NgModule } from "@angular/core";
import {CommonModule} from "@angular/common";

import {ToNumberPipe} from "./shared/pipes/customNumber.pipe";
@NgModule(
    {
        // all components, pipes and directive which are using this module
        declarations: [ToNumberPipe],
        imports: [CommonModule],
        exports: [ToNumberPipe]
    })
export class MainPipeModule {
}

Html code

<span [ngClass]="getClass(rowValue)" class="badge isLink" (click)="selectTask(rowValue.taskId)">{{rowValue.value | ToNumberPipe : "1.0-4"}}</span>

I tried to add the Pipe directly to the app.module, but with same result...

zone.js:1 Unhandled Promise rejection: Template parse errors:
The pipe 'ToNumberPipe' could not be found

Also I tried to remove the arguments and add a simple pipe as well... always the same error

Angular 2 Version: 2.2.4

slaesh

You have to use at least v2.3.0-rc.0

Upon this version following feature is included: core: properly support inheritance

I guess your Pipe is properly included and so on, but those decorators (eg. your name) aren't published correct..

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related