我使用的是MatPaginator组件,我试图弄清楚如何翻译这些标签(文档不够清楚)。如何使用MatPaginatorIntl?
我发现this article展示了如何做到这一点,我遵循的步骤:
1 - 我创建了一个名为custom-paginator.ts
文件,并把下面的有:
import { MatPaginator, MatPaginatorIntl } from '@angular/material';
export class CustomPaginator extends MatPaginatorIntl {
constructor() {
super();
this.nextPageLabel = ' My new label for next page';
this.previousPageLabel = ' My new label for previous page';
this.itemsPerPageLabel = 'Task per screen';
}
}
2 - 在app.module.ts
我把:
@NgModule({
// ...
providers: [
{
provide: MatPaginatorIntl,
useClass: CustomPaginator
}
]
})
export class AppModule
但是,它根本不会改变什么。我错过了什么?
您应该删除标签的初始化来自构造函数,它应该工作。 –