NgXs:TypeError:类构造函数MyState不能在没有“ new”的情况下调用

时间:2019-11-15 08:21:56

标签: angular ngxs

我正在将NgXs商店集成到我的应用中。我创建了一些简单状态并尝试从中选择数据,但是启动应用程序时出现运行时错误:

TypeError: Class constructor MyState cannot be invoked without 'new'
    at ngxs-store.js:2166
    at Array.map (<anonymous>)
    at selectFromAppState (ngxs-store.js:2162)
    at Store.selectSnapshot (ngxs-store.js:2343)
    ...

1 个答案:

答案 0 :(得分:1)

最后,我发现我忘了为NgxsModule提供状态类。

@NgModule({
    imports: [
        CommonModule,
        NgxsModule.forRoot([
            ...
            MyState // this line was missing, so the store cannot instantiate the state
        ], {
            developmentMode: !environment.production
        })
    ],
    exports: [
        NgxsModule
    ]
})
export class StoreModule {}