我试图将i18n转换服务键作为html组件上的参数函数传递。
我试过以下方法,但得到的不是文本,而是键
我在component.ts中分配了一个带有标题的变量
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 )。
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>发布于 2021-03-27 22:56:34
将click()直接应用于<a>标记总是有困难的。这样试一试:
<a href="javascript: void(0)">
<i class="nav-link" (click)="function(getTitle())">{{'title-key' | translate}}</i>
</a>实际上,您将使用单击函数,而不是锚的href事件。
您的组件
public title: string;
constructor(private translate: TranslateService,) {
}
getTitle(): string {
return this.translate.instant('title-key');
}https://stackoverflow.com/questions/66836572
复制相似问题