Angular 如何在html中将translate i18n键用作函数参数
我试图将i18n翻译服务密钥作为html组件上的参数函数传递 我试过下面的方法,但是没有得到文本,而是得到了关键 我在component.ts中分配了一个标题为的变量Angular 如何在html中将translate i18n键用作函数参数,angular,internationalization,i18next,angular-translate,Angular,Internationalization,I18next,Angular Translate,我试图将i18n翻译服务密钥作为html组件上的参数函数传递 我试过下面的方法,但是没有得到文本,而是得到了关键 我在component.ts中分配了一个标题为的变量 import { TranslateService } from '@ngx-translate/core'; constructor(public translate: TranslateService,) { } public title= this.translate.instant('title-key'); 在co
import { TranslateService } from '@ngx-translate/core';
constructor(public translate: TranslateService,) {
}
public title= this.translate.instant('title-key');
在component.html中。我把这个变量作为一个参数函数
<a class="nav-link" (click)="functionName(title)" > {{'title-key' | translate}}</a>
{{'title-key'| translate}
应发送的标题为任务
但它会被发送键->标题键
functionName(tabSelected) {
switch(tabSelected) {
case this.title:
this.tab = true;
break;
default:
}
}
<kendo-tabstrip #tabstrip [keepTabContent]="true">
<kendo-tabstrip-tab [title] = "title" *ngIf="tab" [selected]="true">
<ng-template kendoTabContent *loadOnDemand>
<app-component></app-component>
</ng-template>
</kendo-tabstrip-tab>
<kendo-tabstrip>
functionName(选中选项卡){
开关(已选定){
本案标题:
this.tab=true;
打破
违约:
}
}
将单击()
直接应用到
标记时总会遇到问题。试着这样做:
<a href="javascript: void(0)">
<i class="nav-link" (click)="function(getTitle())">{{'title-key' | translate}}</i>
</a>
对不起,我不明白你的目标。你想要实现什么?请描述一下工作流程。是否只想在UI中显示一些翻译?@Lynx242是的,我正在尝试显示所选语言的选项卡。请查看编辑后的问题。谢谢您的建议。函数名只是一个示例,我现在将编辑这个问题。但是这不起作用..它调用你的函数了吗?如果是这样,console.log()会说什么?它会打印“title key”而不是“tasks”?好了,现在我知道你的问题出在哪里了!ngx翻译不够快!当组件以转换键开始时,您尝试直接初始化变量。这是一个很早的服务。试着换一种方式。我将更新我的示例。已更新。请看一看。
public title: string;
constructor(private translate: TranslateService,) {
}
getTitle(): string {
return this.translate.instant('title-key');
}