Angular Material MatPaginator 无法翻译

Angular Material MatPaginator can not be translated

我想在 matpaginator 标签中翻译 itemsPerPageLabel、nextPageLabel、previousPageLabel、firstPageLabel、lastPageLabel

但我试图像这样创建 class 但它不起作用。我的意思是订阅有效,但是当我更改语言时,无法更改标签

@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

您可以在构造函数中使用 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();
        });

     });
}

}