简体   繁体   English

将 translate pipe 注入 NgRx Effect 并抛出 NullInjectorError

[英]Injecting translate pipe to NgRx Effect and it throws NullInjectorError

I'm Injecting translate pipe to NgRx Effect and it throws NullInjectorError even though the pipe is provided in the module that holds the effect.我将 translate pipe 注入到 NgRx Effect 中,它会抛出 NullInjectorError,即使 pipe 是在包含该效果的模块中提供的。 the package that I'm using for the translation is @ngx-translate/core.我用于翻译的 package 是@ngx-translate/core。

Note: I was able to use the translatePipe in component scope.注意:我能够在组件 scope 中使用 translatePipe。

module.ts:模块.ts:

@NgModule({
    declarations: [
        OptimizationTabMainComponent,
    ],
    imports: [
        OptimizationTabRoutingModule,
        SharedModule,
        TranslateModule,
        StoreModule,
        StoreModule.forFeature(StoreFeatures.Optimization, optimizationReducers),
        EffectsModule.forFeature([OptimizationMainEffects]),

    ],
    providers: [
        TranslatePipe
    ]
})
class OptimizationTabModule { }

export {OptimizationTabModule};

effect.ts:效果.ts:

@Injectable()
export class OptimizationMainEffects {
    constructor(        
        private translateService: TranslatePipe,
    ) {
    }
}

app.module.ts应用程序模块.ts

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        HttpClientModule,
        AppRoutingModule,
        SharedModule,
        TranslateModule.forRoot({
            defaultLanguage: 'en',
            loader:          {
                provide:    TranslateLoader,
                useClass: LazyTranslateLoader
            },
            isolate: true
        }),
]
...

shared.module.ts共享模块.ts

const importsExports = [
    CommonModule,
    FlexModule,
    TranslateModule,
    FlexLayoutModule,
    NotificationsModule,
    ComponentsModule,
    MatExpansionModule,
    MatCardModule,
    MatIconModule,
    MatTooltipModule
];

@NgModule({
    imports: importsExports,
    exports: importsExports
})
export class SharedModule { }

在此处输入图像描述

You need to import the translate module.您需要导入翻译模块。 Docs: https://github.com/ngx-translate/core#sharedmodule文档: https://github.com/ngx-translate/core#sharedmodule

@NgModule({
    imprts: [
        CommonModule,
        TranslateModule
    ]
})
export class SharedModule { }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM