angular - angular2'de özel bir pipe üzerinde currency veya number gibi bir pipe'ı genişletmek


Özel pipe'ımda numberPipe'i çağırmak istiyorum, bu cevabı buluyorum

Angular2 özel pipe içinde temel pipe kullanır

ama bu çözüm benim için işe yaramıyor. "bigInteger borusu bulunamadı" hatası alıyorum

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

@Pipe({
 name: "bigInteger"
 })
 export class BigInteger extends CurrencyPipe implements PipeTransform {
   transform(value: any): string {
    return value
 }
}

Cevap #1

Belki modası geçmiş, ama bu benim için işe yaradı (Angular 5):

import { Pipe, PipeTransform } from '@angular/core';
import { DecimalPipe } from '@angular/common'

@Pipe({
  name: 'bigInteger'
})
export class BigInteger extends DecimalPipe implements PipeTransform {
  transform(value: any, args?: any): any {

    let result;
    result = super.transform(value, args);

    //any transformations you need

    return result;
  }

}

Sonra onu normal bir number filtresi gibi kullanırsınız, ama istediğiniz gibi özelleştirebilirsiniz:

<span>{{someValue | bigInteger : '1.2-2'}}</span>

Cevap #2

güncelle

en azından Angular4'te bu bir süredir düzeltilmiş olmalı

orijinal

DI ve diğer sınıflardan türeyen sınıflarla ilgili bilinen bir sorun var

https://github.com/angular/angular/issues/8694

Bu düzeltilene kadar, kalıtım yerine kompozisyon kullanabilirsiniz:

@Pipe({
  name: "bigInteger"
})
export class BigInteger implements PipeTransform {

  constructor(private currencyPipe:CurrencyPipe) {}

  transform(value: any): string {
     return this.currencyPipe.transform(value);
  }
}

İlgili makaleler