在本文中,我們將了解 Angular 10 中的 getCurrencySymbol 是什麽以及如何使用它。 getCurrencySymbol 用於 r獲取給定貨幣代碼的貨幣符號
用法:
getCurrencySymbol(code, locale, format)
參數:
- code:貨幣代碼
- locale:要使用的區域設置格式規則的區域設置代碼。
- format:格式。
返回值:
- 細繩:格式化的日期字符串。
NgModule:getCurrencySymbol 使用的模塊是:
- CommonModule
方法:
- 創建要使用的 Angular 應用程序。
- 在 app.module.ts 中導入 LOCALE_ID 因為我們需要導入語言環境以使用 get getCurrencySymbol。
import { LOCALE_ID, NgModule } from '@angular/core';
- 在 app.component.ts 中導入 getCurrencySymbol 和 LOCALE_ID
- 將 LOCALE_ID 作為公共變量注入。
- 在 app.component.html 中使用字符串插值顯示局部變量
- 使用 ng serve 為 angular 應用程序提供服務以查看輸出。
範例1:
app.component.ts
import {
getCurrencySymbol
}
from '@angular/common';
import {Component}
from '@angular/core';
@Component({
selector:'app-root',
templateUrl:'./app.component.html'
})
export class AppComponent {
curr = getCurrencySymbol("USD", "wide");
}
應用程序組件.html
<h1>
GeeksforGeeks
</h1>
<p>{{curr }} 100</p>
輸出:
範例2:
app.component.ts
import {
getCurrencySymbol
}
from '@angular/common';
import {Component}
from '@angular/core';
@Component({
selector:'app-root',
templateUrl:'./app.component.html'
})
export class AppComponent {
curr = getCurrencySymbol("INR", "narrow");
}
應用程序組件.html
<h1>
GeeksforGeeks
</h1>
<p>{{curr }} 304</p>
輸出:
參考:https://angular.io/api/common/getCurrencySymbol
相關用法
- Angular10 formatPercent()用法及代碼示例
- Angular10 formatNumber()用法及代碼示例
- Angular10 formatDate()用法及代碼示例
- AngularJS angular.isObject()用法及代碼示例
- AngularJS angular.isUndefined()用法及代碼示例
- AngularJS angular.isNumber()用法及代碼示例
- AngularJS angular.isString()用法及代碼示例
- AngularJS angular.isDefined()用法及代碼示例
- AngularJS angular.isDate()用法及代碼示例
- AngularJS angular.toJson()用法及代碼示例
- AngularJS angular.element()用法及代碼示例
- AngularJS angular.isFunction()用法及代碼示例
注:本文由純淨天空篩選整理自taran910大神的英文原創作品 Angular 10 getCurrencySymbol() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。