我正在将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)
...
答案 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 {}