NullInjectorError:没有TranslateService提供程序

时间:2019-01-07 07:11:10

标签: angular

import { BrowserModule } from '@angular/platform-browser';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { Injector, APP_INITIALIZER, NgModule } from '@angular/core';
import { LOCATION_INITIALIZED } from '@angular/common';
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import {AngularSlickgridModule, GridOdataService, ResizerService} from 'angular-slickgrid';

import { AppComponent } from './app.component';
import { FirstgridComponent } from './firstgrid/firstgrid.component';

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}
export function appInitializerFactory(translate: TranslateService, injector: Injector) {
  return () => new Promise<any>((resolve: any) => {
    const locationInitialized = injector.get(LOCATION_INITIALIZED, Promise.resolve(null));
    locationInitialized.then(() => {
      const langToSet = 'en';
      translate.setDefaultLang('en');
      translate.use(langToSet).subscribe(() => {
        // console.info(`Successfully initialized '${langToSet}' language.'`);
      }, err => {
        console.error(`Problem with '${langToSet}' language initialization.'`);
      }, () => {
        resolve(null);
      });
    });
  });
}

@NgModule({
  declarations: [
    AppComponent,
    FirstgridComponent
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    })
  ],
  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: appInitializerFactory,
      deps: [TranslateService, Injector],
      multi: true
    },
    GridOdataService,
    ResizerService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

我正在按角度创建slikgrid组件。我导入了所有库,但是出现以下错误。

GridBasicComponent.html:5 ERROR Error: StaticInjectorError(AppModule)[AngularSlickgridComponent -> TranslateService]: 
  StaticInjectorError(Platform: core)[AngularSlickgridComponent -> TranslateService]: 
    NullInjectorError: No provider for TranslateService!
    at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1062)
    at resolveToken (core.js:1300)
    at tryResolveToken (core.js:1244)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141)
    at resolveToken (core.js:1300)
    at tryResolveToken (core.js:1244)
    at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1141)
    at resolveNgModuleDep (core.js:8369)
    at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:9057)
    at resolveDep (core.js:9422)

在编写该代码后,我得到一个错误,即“ slick.cellrangedecorator.js:72 Uncaught ReferenceError:未定义jQuery”。 而在终端错误就像- node_modules / angular-slickgrid / app / modules / angular-slickgrid / filter-conditions / index.d.ts(2,35)中的错误:错误TS1005:“;”预期的。

0 个答案:

没有答案