没有TranslateService的提供者

时间:2019-04-10 12:52:25

标签: angular ngx-translate

我根据文档在项目中添加了ng-translate,但仍然有错误

    //import
        import {TranslateLoader, TranslateModule, TranslateService} from '@ngx-translate/core';

    //also provides 
        providers: [
            {provide: LOCALE_ID, useValue: 'en-US'},
            BaseRequestOptions,
            { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },
          { provide: HTTP_INTERCEPTORS, useClass: CommonInterceptor, multi: true },
          NGXLogger,
          TranslateService
        ],

//and 
export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

1 个答案:

答案 0 :(得分:0)

确保已在app.module.ts的imports块中添加了代码段 例如:

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,

    // configure the imports
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      }
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
});