angular-l10n
Version:
An Angular library to translate messages, dates and numbers
59 lines • 2.15 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 { Logger } from '../models/logger';
import { takeUntilDestroyed } from '../models/take-until-destroyed';
/**
* Property decorator for components to provide the parameter to the l10nDate pipe.
* @return {?}
*/
export function Timezone() {
/**
* @param {?} target
* @param {?=} propertyKey
* @return {?}
*/
function DecoratorFactory(target, propertyKey) {
/** @type {?} */
var targetNgOnInit = target.ngOnInit;
if (typeof targetNgOnInit === "undefined") {
Logger.log(target.constructor ? target.constructor.name : 'Timezone decorator', 'missingOnInit');
}
/**
* @this {?}
* @return {?}
*/
function ngOnInit() {
var _this = this;
/** @type {?} */
var locale = InjectorRef.get(LocaleService);
if (typeof propertyKey !== "undefined") {
this[propertyKey] = locale.getCurrentTimezone();
locale.timezoneChanged.pipe(takeUntilDestroyed(this)).subscribe(function (zoneName) {
_this[propertyKey] = zoneName;
/** @type {?} */
var cdr = Object.keys(_this)
.find(function (key) { return _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=timezone.decorator.js.map