Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extend a pipe like currency or number on a custom pipe on angular2

I would like to call the numberPipe on my custom pipe I find this answer

Angular2 use basic pipe in custom pipe

but I this solution don't work for me. I have an error "The pipe 'bigInteger' could not be found"

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
 }
}
like image 817
imtah Avatar asked Aug 16 '16 09:08

imtah


People also ask

Which is the correct command to create a custom pipe?

Use ng generate pipe followed by pipe name command to create custom pipes in angular. The command will create a file named custom. pipe. ts along with sample code to implement custom pipe at application root level.

Can I add two pipes Angular?

Angular Pipes Multiple custom pipes Having different pipes is a very common case, where each pipe does a different thing. Adding each pipe to each component may become a repetitive code. It is possible to bundle all frequently used pipes in one Module and import that new module in any component needs the pipes.


1 Answers

Maybe obsolete, but this worked for me (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;
  }

}

Then you just use it like regular number pipe, but can customize as you wish:

<span>{{someValue | bigInteger : '1.2-2'}}</span>
like image 86
Ivan Amelyanenka Avatar answered Sep 18 '22 11:09

Ivan Amelyanenka