Dependency injection MatPaginator中的翻译服务

Dependency injection MatPaginator中的翻译服务,dependency-injection,jhipster,Dependency Injection,Jhipster,我基于以下实施: 他试图在我的隐含MatPaginatorIntl中添加TranslateService,它向我显示了以下错误。这段代码是jhipster的一部分,我在共享文件夹中添加了这个实现 错误: Uncaught Error: Can't resolve all parameters for SharedPaginatorIntl: (?). at syntaxError (eval at ./node_modules/@angular/compiler/@angular/compil

我基于以下实施:

他试图在我的隐含MatPaginatorIntl中添加TranslateService,它向我显示了以下错误。这段代码是jhipster的一部分,我在共享文件夹中添加了这个实现

错误:

Uncaught Error: Can't resolve all parameters for SharedPaginatorIntl: (?).
at syntaxError (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:1917:34)
at CompileMetadataResolver._getDependenciesMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:15984:35)
at CompileMetadataResolver._getTypeMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:15852:26)
at CompileMetadataResolver._getInjectableMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:15838:21)
at CompileMetadataResolver.getProviderMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:16129:40)
at eval (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:16058:49)
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:16018:19)
at CompileMetadataResolver.getNgModuleMetadata (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:15673:50)
at CompileMetadataResolver.getNgModuleSummary (eval at ./node_modules/@angular/compiler/@angular/compiler.es5.js (vendor.bundle.js:135), <anonymous>:15526:52)
shared.module.ts

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { DatePipe } from '@angular/common';
import {TranslateModule} from '@ngx-translate/core';

import {
BuildingcSharedLibsModule,
BuildingcSharedCommonModule,
CSRFService,
AuthServerProvider,
AccountService,
UserService,
StateStorageService,
LoginService,
LoginModalService,
Principal,
JhiTrackerService,
HasAnyAuthorityDirective,
JhiLoginModalComponent,
} from './';

@NgModule({
imports: [
    BuildingcSharedLibsModule,
    BuildingcSharedCommonModule,
    TranslateModule
],
declarations: [
    JhiLoginModalComponent,
    HasAnyAuthorityDirective
],
providers: [
    LoginService,
    LoginModalService,
    AccountService,
    StateStorageService,
    Principal,
    CSRFService,
    JhiTrackerService,
    AuthServerProvider,
    UserService,
    DatePipe,
    TranslateModule
],
entryComponents: [JhiLoginModalComponent],
exports: [
    BuildingcSharedCommonModule,
    JhiLoginModalComponent,
    HasAnyAuthorityDirective,
    DatePipe
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]

})
export class BuildingcSharedModule {}
我的实施:

 import {MatPaginator, MatPaginatorIntl} from '@angular/material';
 import {Component} from '@angular/core';
 import {TranslateService} from '@ngx-translate/core';

export class SharedPaginatorIntl extends MatPaginatorIntl {

itemsPerPageLabel = 'Total por página';
nextPageLabel     = 'Siguiente Página';
previousPageLabel = 'Anterior Página';

constructor(private translateService: TranslateService) {
    super();
}

getRangeLabel = function (page, pageSize, length) {
    if (length === 0 || pageSize === 0) {
        return '0 de ' + length;
    }
    length = Math.max(length, 0);
    const startIndex = page * pageSize;
    // If the start index exceeds the list length, do not try and fix the end index to the end.
    const endIndex = startIndex < length ?
        Math.min(startIndex + pageSize, length) :
        startIndex + pageSize;
    return startIndex + 1 + ' - ' + endIndex + ' de ' + length;
};
}
从'@angular/material'导入{MatPaginator,MatPaginatorIntl};
从'@angular/core'导入{Component};
从'@ngx translate/core'导入{TranslateService};
导出类SharedPaginatorIntl扩展了MatPaginatorIntl{
itemsPerPageLabel='总收入';
nextPageLabel='Siguiente Página';
previousPageLabel=‘前Página’;
构造函数(私有translateService:translateService){
超级();
}
getRangeLabel=函数(页面、页面大小、长度){
如果(长度===0 | |页面大小===0){
返回'0 de'+长度;
}
长度=数学最大值(长度,0);
常量startIndex=页面*页面大小;
//如果开始索引超过列表长度,请不要尝试将结束索引固定到末尾。
常数endIndex=startIndex
您必须使用

@Injectable()
能够使用角度DI

因此,在您的情况下,它将是:

@Injectable()
export class SharedPaginatorIntl extends MatPaginatorIntl {
...
@Injectable()
export class SharedPaginatorIntl extends MatPaginatorIntl {
...