Created
February 1, 2019 18:47
-
-
Save karkianish/f82660674165c059c87d4a889eddee47 to your computer and use it in GitHub Desktop.
How to use pipe in component class?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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