From 92cb0712be19417471bf64fd9cc0cd4bae194e0f Mon Sep 17 00:00:00 2001 From: Raphael Luba Date: Thu, 17 Dec 2020 11:23:18 +0100 Subject: [PATCH] Fix incorrect warning about missing interpolation variables Fixes #273 caused by interpolating the value before its params were bound. --- src/t/t-custom-attribute.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/t/t-custom-attribute.ts b/src/t/t-custom-attribute.ts index 6f5a38b3..f18fd4db 100644 --- a/src/t/t-custom-attribute.ts +++ b/src/t/t-custom-attribute.ts @@ -49,12 +49,17 @@ export class TCustomAttribute { }; } - const p = this.params !== null ? this.params.value : undefined; this.subscription = this.ea.subscribe(I18N_EA_SIGNAL, () => { this.service.updateValue(this.element, this.value, this.params !== null ? this.params.value : undefined); }); - this.service.updateValue(this.element, this.value, p); + // Don’t update the translation if params are given, but not yet bound. + // (Otherwise, we’ll get warnings about missing variables during interpolation.) + // In that case, the initial translation will happen via the paramsChanged handler. + if (!this.params || this.params.value !== undefined) { + const p = this.params ? this.params.value : undefined; + this.service.updateValue(this.element, this.value, p); + } } public paramsChanged(newValue: any, newParams: any) { @@ -62,7 +67,7 @@ export class TCustomAttribute { } public valueChanged(newValue: any) { - const p = this.params !== null ? this.params.value : undefined; + const p = this.params ? this.params.value : undefined; this.service.updateValue(this.element, newValue, p); }