Angular 2 更新所有指令(错误)

Angular 2 updating all directive (Error)

我正在使用 @ViewChildren 访问页面中的所有指令并使用 forEach 循环我想更新这些指令的 innerHTML

HTML 代码:

<h3><span [appI18n]="'HEY'"></span>, Subrata</h3>
<h4><span><span [appI18n]="'WELCOME_TO'">Welcome</span> to MyWebsite</span></h4>

home.component.ts:

@ViewChildren(I18nDirective) _i18nDirective;

if (this._i18nDirective && this._i18nDirective._results && this._i18nDirective._results.length > 0) {
                    this._i18nDirective._results.forEach((_i18nItem) => {
                        this._Logger.debug(_i18nItem);
                        _i18nItem.setterMultiParams(_i18nItem._el.nativeElement, _i18nItem.i18nLanguage);
                    });
                }

i18n.directive.ts

setterMultiParams = (_element, _key) => {
        this._HttpService.languageGetter(this._ConfigService.defaultLanguage).subscribe(response => {
            const appLangData: any = {};
            appLangData.data = response;
            appLangData.action = 'SET_APP_LANGUAGE';
            this._ConfigService.setter(appLangData).delay(100).subscribe(
                (res) => {
                    const _keyNames = Object.keys(_key);
                    _keyNames.forEach((i18nItem) => {
                        if (this.i18nLanguage.hasOwnProperty(i18nItem)) {
                            this._Renderer.setElementProperty(_element, 'innerHTML', this.i18nLanguage[i18nItem]);
                        }
                    });
                }
            );
        });

}

这会将两个指令的 innerHTML 更新为相同的值。

if(_element._el.nativeElement.attributes[1].nodeValue === i18nItem) {
                                _element._Renderer.setProperty(_element._el.nativeElement, 'innerHTML', this.i18nLanguage[i18nItem]);
  }

需要检查 nodeValue