我在项目中使用ngx-translate。我想使用Angular Material组件(mat-form-field)作为平移值的一部分。 示例:
键:NumberChoice
值:Choose a number: {{choice}}.
在HTML中使用:
<span>{{ 'NumberChoice' | translate: {choice: this.choiceSelectorComponent} }}</span>
choiceSelectorComponent
是上述的mat-form-field。
我尝试将mat-form-field的代码放入新的ng组件中,并在匹配的.ts
文件中为其定义了一个吸气剂。
我还尝试将其作为HTML标记获取,如下所示:
get choiceSelectorComponent() {
return document.createElement('page-size-selector').outerHTML;
}
仅将标记作为翻译的一部分:
选择一个数字:
。
换句话说,我如何动态地将UI控件包含在转换后的值中,并将其用作传递给ngx-translate
的参数。
答案 0 :(得分:1)
根据ngx-translate
documentation,您应该执行以下操作。
在您的HTML模板中:
<span>{{ 'NumberChoice' | translate:choice} }}</span>
然后在组件文件中定义参数:
param = this.choiceSelectorComponent() // Or whatever value you want
这将允许管道正确确定参数的值。
希望这会有所帮助。