Skip to content

Instantly share code, notes, and snippets.

@karkianish
Created February 1, 2019 18:47
Show Gist options
  • Save karkianish/f82660674165c059c87d4a889eddee47 to your computer and use it in GitHub Desktop.
Save karkianish/f82660674165c059c87d4a889eddee47 to your computer and use it in GitHub Desktop.
How to use pipe in component class?
// import desired pipe and add it to the provider array in your module
import {CurrencyPipe} form "@angular/common";
@NgModule({
imports: [],
declarations: [],
exports: [],
providers: [ CurrencyPipe ]
})
export class MyModule {}
// in your component, inject it via ctor and use the tansform method on the pipe
@Component({
selector: "blah",
templateUrl: "blah"
})
export class MyComponent {
constructor(private currencyPipe: CurrencyPipe) {}
someMethod(): void {
const formattedValue = this.currencyPipe.transform("1232", "USD", "symbol", "1.2-2");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment