[英]How to binding an array of string using translate pipe from ngx-translate
我有這個子組件,它有一個接收字符串數組的輸入:
<child-component list="['yes','no']"> </child-component>
我正在嘗試使用從 ngx-translate 翻譯的 pipe 發送數據。
<child-component list="[{{'yes' | translate}},{{'no' | translate}}]"> </child-component>
但我沒有工作。
我不想在子組件代碼中使用 pipe,那么,有沒有辦法發送它已經翻譯?
只需直接在組件中翻譯您的標簽,例如:
export class AppComponent implements OnInit {
labels: string[] = ['yes', 'no'];
constructor(private translateService: TranslateService) {}
ngOnInit(): void {
this.translateService
.get(this.labels)
.subscribe((res: string[]) => {
console.log(res);
//=> translated labels
});
// Or
this.translateService.instant('yes');
this.translateService.instant('no');
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.