我有一个自定义的十进制格式管道,它使用Angular 十进制管道.此管道是共享模块的一部分.我将在功能模块中使用它,并且在运行应用程序时不会出现提供程序错误.
Please ignore if there are any typo
./src/pipes/custom.pipe.ts
import { DecimalPipe } from '@angular/common';
..
@Pipe({
name: 'customDecimalPipe'
})
...
export class CustomPipe {
constructor(public decimalPipe: DecimalPipe) {}
transform(value: any, format: any) {
...
}
./modules/shared.module.ts
import { CustomPipe } from '../pipes/custom.pipe';
...
@NgModule({
imports: [ .. ],
declarations: [ CustomPipe ],
exports: [ CustomPipe ]
})
export class SharedModule { }
我将自定义管道注入其中一个组件中,并调用transform方法来获得转换后的值.共享模块导入到功能模块中.