我想在matpaginator标签中翻译itemsPerPageLabel,nextPageLabel,previousPageLabel,firstPageLabel,lastPageLabel
但是我试图创建这样的类,但是它不起作用。我的意思是订阅有效,但是当我更改语言时,标签无法更改
@Injectable()
export class MatPaginatorCustom extends MatPaginatorIntl {
constructor(public translateService: TranslateService) {
super();
this.translateService.stream('vehicle.ubdate.matSnackBar.message')
.subscribe(labelValue => {
console.log(labelValue);
this.itemsPerPageLabel = labelValue;
});
}
}
我将Angular 8与ngx-translate一起使用
答案 0 :(得分:1)
您可以在构造函数中使用 onLangChange 方法。 例如:
@Injectable()
export class MatPaginatorCustom extends MatPaginatorIntl {
constructor(public translateService: TranslateService) {
super();
this.translateService.onLangChange.subscribe(event => {
this.translate.get('vehicle.ubdate.matSnackBar.message')
.subscribe(labelValue => {
console.log(labelValue);
this.itemsPerPageLabel = labelValue;
// must call this method after change label.
this.changes.next();
});
});
}
}