Ionic 2, Using Angular 2 Pipe breaks on iOS—“Can't find variable: Intl”

后端 未结 4 626
时光说笑
时光说笑 2020-12-05 09:50

Experiencing the same problem with the date, percent, and currency pipes when using them in a template—

For example, I\'m using a simple percent pipe:



        
4条回答
  •  渐次进展
    2020-12-05 10:23

    Or another solution would be writing those pipes yourself. For the date, for example, you can use moment.js, or here is an example for the currency pipe:

    import { Pipe, PipeTransform } from '@angular/core'
    
    @Pipe({ name: 'currency' })
    
    export class CurrencyPipe implements PipeTransform {
        constructor() {}
    
        transform(value: string, currencyString: string ) { 
            let stringOnlyDigits  = value.replace(/[^\d.-]/g, '');
            let convertedNumber = Number(stringOnlyDigits).toFixed(2);
            return convertedNumber + " " + currencyString;
        }
    } 
    

    This pipe is transforming the currency. The percent pipe would work nearly the same way. The regex is filtering all digits including the point for float numbers.

提交回复
热议问题