cexbrayat 270176bbe4 docs: more info on currency digits (#24661)
Adds an example of using the `currency` pipe with a currency that has no cents like CLP,
which will format the amount with no digits if `digitsInfo` is not provided:

    <!-- outputs CA$14.00 -->
    {{ 14 | currency:'CAD' }}
    <!-- outputs CLP14 -->
    {{ 14 | currency:'CLP' }}

Amends the docs, adds an example and fix an error with a current example.

PR Close #24661
2018-07-20 10:33:06 -07:00

65 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {registerLocaleData} from '@angular/common';
import {Component} from '@angular/core';
// we need to import data for the french locale
import localeFr from './locale-fr';
// registering french data
registerLocaleData(localeFr);
// #docregion CurrencyPipe
@Component({
selector: 'currency-pipe',
template: `<div>
<!--output '$0.26'-->
<p>A: {{a | currency}}</p>
<!--output 'CA$0.26'-->
<p>A: {{a | currency:'CAD'}}</p>
<!--output 'CAD0.26'-->
<p>A: {{a | currency:'CAD':'code'}}</p>
<!--output 'CA$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2'}}</p>
<!--output '$0,001.35'-->
<p>B: {{b | currency:'CAD':'symbol-narrow':'4.2-2'}}</p>
<!--output '0 001,35 CA$'-->
<p>B: {{b | currency:'CAD':'symbol':'4.2-2':'fr'}}</p>
<!--output 'CLP1' because CLP has no cents-->
<p>B: {{b | currency:'CLP'}}</p>
</div>`
})
export class CurrencyPipeComponent {
a: number = 0.259;
b: number = 1.3495;
}
// #enddocregion
// #docregion DeprecatedCurrencyPipe
@Component({
selector: 'deprecated-currency-pipe',
template: `<div>
<!--output 'CAD0.26'-->
<p>A: {{a | currency:'CAD'}}</p>
<!--output '$0,001.35'-->
<p>B: {{b | currency:'CAD':true:'4.2-2'}}</p>
</div>`
})
export class DeprecatedCurrencyPipeComponent {
a: number = 0.259;
b: number = 1.3495;
}
// #enddocregion