UNPKG

angular-l10n

Version:

An Angular library to translate messages, dates and numbers

92 lines 2.42 kB
/** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,uselessCode} checked by tsc */ import { Directive, ElementRef, Input, Renderer2 } from '@angular/core'; import { takeUntil } from 'rxjs/operators'; import { LocaleService } from '../services/locale.service'; import { BaseDirective } from '../models/base-directive'; export class L10nDateDirective extends BaseDirective { /** * @param {?} locale * @param {?} el * @param {?} renderer */ constructor(locale, el, renderer) { super(el, renderer); this.locale = locale; this.el = el; this.renderer = renderer; } /** * @param {?} format * @return {?} */ set l10nDate(format) { this.format = format; } /** * @return {?} */ setup() { this.replace(); this.locale.defaultLocaleChanged.pipe(takeUntil(this.destroy)).subscribe(() => { this.replace(); }); this.locale.timezoneChanged.pipe(takeUntil(this.destroy)).subscribe(() => { this.replace(); }); } /** * @return {?} */ replace() { this.replaceText(); this.replaceAttributes(); } /** * @return {?} */ replaceText() { if (!!this.key) { this.setText(this.getValue(this.key)); } } /** * @return {?} */ replaceAttributes() { if (this.attributes.length > 0) { this.setAttributes(this.getAttributesData()); } } /** * @param {?} key * @return {?} */ getValue(key) { return this.locale.formatDate(key, this.format); } } L10nDateDirective.decorators = [ { type: Directive, args: [{ selector: '[l10nDate]' },] } ]; /** @nocollapse */ L10nDateDirective.ctorParameters = () => [ { type: LocaleService }, { type: ElementRef }, { type: Renderer2 } ]; L10nDateDirective.propDecorators = { l10nDate: [{ type: Input }], format: [{ type: Input }] }; if (false) { /** @type {?} */ L10nDateDirective.prototype.format; /** @type {?} */ L10nDateDirective.prototype.locale; /** @type {?} */ L10nDateDirective.prototype.el; /** @type {?} */ L10nDateDirective.prototype.renderer; } //# sourceMappingURL=l10n-date.directive.js.map