angular - NgXs:TypeError:没有'new'就不能调用类构造函数MyState
问题描述
我正在将NgXs Store 集成到我的应用程序中。我创建了几个简单的状态并尝试从中选择数据,但是当应用程序启动时,我得到了运行时错误:
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)
...
解决方案
最后我发现我忘记将状态类提供给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 {}
推荐阅读
- javascript - 如何在 NgRx 中推送或更新状态?
- python - 仅在单词正则表达式中包含单引号
- sql-server - ECS 任务无法与本地 SQL Server 建立连接
- python - 如何使用 dask 有效地聚合大量小型 csv 文件(每个 120kb 约 50k 个文件)(代码大小、调度程序+集群运行时)?
- c# - 控制台树视图 C#
- c - 错误使用函数
- dynamic - 通过 PHP 使用 load data infile 导入大数据
- ajax - 每次更改日期时的 Ajax 请求
- python - 是否有可能在字典中? - 创建一个字典并按增量添加每个键
- c# - ASP.NET 配置错误:不正确的模型验证