Angular 2 CurrencyPipe space between currency and number?

后端 未结 10 1094
轻奢々
轻奢々 2021-02-18 21:08

I noticed that there is a pipe called CurrencyPipe in Angular 2, which will filter some decimals from a number. This also adds the ISO currency indicator, ie \'USD\' or any othe

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-18 22:05

    Create a new pipe that receive the currency as input.

    import { Pipe, PipeTransform } from '@angular/core';
    
    @Pipe({
        name: 'space'
    })
    export class SpacePipe implements PipeTransform {
       transform(value: any, args?: any): any {
           console.log(value.substring(0, 1) + ' ' + value.substring( 1));
           return value.substring(0, 1) + ' ' + value.substring( 1);
       }
    }
    

    After that you can call them like this

    {{discount | currency: 'EUR' | space}}
    

    Dont forget to include it in @NgModule -> declarations

提交回复
热议问题