找不到管道“ noComma”

时间:2019-10-07 00:15:40

标签: angular

我创建了一个名为“ noComma”的自定义管道。 我尝试创建一个PipeModule,然后将NoCommaPipe放入声明中,然后进行导出,然后将PipeModule放入app.module.ts的导入中,但是仍然会发生错误。

NoCommaPipe.ts:

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

@Pipe({
    name: 'noComma'
})

export class NoCommaPipe implements PipeTransform {

    transform(val: number): string {
        let transformedVal: string;
        if(val === undefined || val === null) {
            transformedVal = ""
        } else {
            transformedVal = val.toString().replace(/,/g, "");
        }
        return transformedVal;
    }
}

PipeModule.ts

import { NgModule } from '@angular/core';
import { NoCommaPipe } from './NoCommaPipe';
import { CommonModule } from '@angular/common';
import { IonicModule } from 'ionic-angular';

@NgModule({
    declarations: [
        NoCommaPipe
    ],
    exports: [
        NoCommaPipe
    ],
    imports: [
        IonicModule
    ]
})
export class PipeModule {
    static forRoot() {
        return {
            ngModule: PipeModule,
            providers: [],
        };
     }    
}

app.module.ts

import { PipeModule } from '../app/local/pipe/PipeModule';

@NgModule({
imports: [PipeModule.forRoot()]})

0 个答案:

没有答案