angular - Akita 和 Angular 错误:StaticInjector 和 NullInjector 存储、查询
问题描述
我在 Angular 项目上的秋田状态管理实施中遇到了错误。我将提供一个简短的答案,以便像我这样的人可以解决这个问题。
在秋田文档和示例中对此没有明确的理解。
export interface ItemState extends EntityState<Item> {}
@StoreConfig({ name: 'items' })
export class ItemsStore extends EntityStore<ItemState> {
constructor() {
super();
}
}
我收到错误:StaticInjectorError(Platform: core)[ItemsService -> ItemsStore]: NullInjectorError: No provider for ItemsStore!
它应该工作
解决方案
文档中没有提到它,但为了让它工作,我们只需要添加 provideIn: 'root'
export interface ItemState extends EntityState<Item> {}
@Injectable({
providedIn: 'root'
})
@StoreConfig({ name: 'items' })
export class ItemsStore extends EntityStore<ItemState> {
constructor() {
super();
}
}
ItemsQuery 也是如此。希望这对某人有帮助
推荐阅读
- ios - Adobe Flash IOS 构建 TMS-90184:无效架构
- oracle - PL/SQL 我做错了什么?
- java - Arquillian、CDI 2.0 和 JUnit 5/Jupiter
- xml - 为什么这个 XSLT 在模板完成后会添加内容?
- sql - 在 Join 中包括区分大小写
- algorithm - 什么算法可以用来检测多边形之间的间隙?
- python - 使用 Python 分析之前的数据 (excel) 准备
- ubuntu - 启动统一 om chromebook 的问题
- python - 无法在 django admin 中查看用户
- java - 从一种时间格式转换为另一种时间格式