首页 > 解决方案 > 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!

它应该工作

标签: angularakita

解决方案


文档中没有提到它,但为了让它工作,我们只需要添加 provideIn: 'root'

export interface ItemState extends EntityState<Item> {}
@Injectable({
  providedIn: 'root'
})
@StoreConfig({ name: 'items' })
export class ItemsStore extends EntityStore<ItemState> {
  constructor() {
    super();
  }
}

ItemsQuery 也是如此。希望这对某人有帮助


推荐阅读