我创建了一个名为“ 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()]})