angular-l10n
Version:
An Angular library to translate messages, dates and numbers
58 lines • 2.11 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
*/
import { LocaleService } from '../services/locale.service';
import { InjectorRef } from '../models/injector-ref';
import { takeUntilDestroyed } from '../models/take-until-destroyed';
import { Logger } from '../models/logger';
/**
* Property decorator for components to provide the parameter to the l10nCurrency pipe.
* @return {?}
*/
export function Currency() {
/**
* @param {?} target
* @param {?=} propertyKey
* @return {?}
*/
function DecoratorFactory(target, propertyKey) {
/** @type {?} */
const targetNgOnInit = target.ngOnInit;
if (typeof targetNgOnInit === "undefined") {
Logger.log(target.constructor ? target.constructor.name : 'Currency decorator', 'missingOnInit');
}
/**
* @this {?}
* @return {?}
*/
function ngOnInit() {
/** @type {?} */
const locale = InjectorRef.get(LocaleService);
if (typeof propertyKey !== "undefined") {
this[propertyKey] = locale.getCurrentCurrency();
locale.currencyCodeChanged.pipe(takeUntilDestroyed(this)).subscribe((currency) => {
this[propertyKey] = currency;
/** @type {?} */
const cdr = Object.keys(this)
.find((key) => this[key] && this[key]['markForCheck'] !== undefined);
if (cdr) {
this[cdr].markForCheck();
}
});
}
if (targetNgOnInit) {
targetNgOnInit.apply(this);
}
}
target.ngOnInit = ngOnInit;
if (typeof propertyKey !== "undefined") {
Object.defineProperty(target, propertyKey, {
writable: true,
value: ''
});
}
}
return DecoratorFactory;
}
//# sourceMappingURL=currency.decorator.js.map