当前版本的Angular 和ngrx为16.0.0.

StoreModule.forRoot({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer
    }),
    EffectsModule.forRoot([
      AppEffects,
      AnotherEffects
    ]),

我开始迁移到独立的Angular 应用程序.因此,我需要从app.mode.ts中删除StoreModule和EffectsModule.但我可以找到方法来提供几个减速器和相对效果使用独立的API.

try 了不同的方法来提供,但没有一种方法能像预期的那样起作用.当应用程序试图读取它时,状态是未知的.

推荐答案

1. First, make sure you have imported the necessary NgRx modules and your reducers and effects.

import { provideState } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import { appReducer } from './app.reducer';
import { anotherFeatureReducer } from './another-feature.reducer';
import { AppEffects } from './app.effects';
import { AnotherEffects } from './another.effects';

2.In your app module, use the provideState() function to provide your root reducers

import { provideState } from '@ngrx/store';

@NgModule({
  imports: [
    //Remove StoreModule.forRoot()
    //Remove EffectsModule.forRoot()
    // Add provideState() to provide your root reducers
    provideState({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer,
    }),
  ],
})
export class AppModule {}

3. Similarly, use the provideEffects() function to provide your root effects

import { provideEffects } from '@ngrx/effects';

@NgModule({
  imports: [
    //Remove StoreModule.forRoot()
    //Remove EffectsModule.forRoot()
    // Add provideState() to provide your root reducers
    provideState({
      app: appReducer,
      anotherFeatureName: anotherFeatureReducer,
    }),

    // Add provideEffects() to provide your root effects
    provideEffects([AppEffects, AnotherEffects]),
  ],
})
export class AppModule {}

Typescript相关问答推荐

TypScript如何在 struct 上定义基元类型?

有没有可能使用redux工具包的中间件同时监听状态的变化和操作

与字符串文字模板的结果类型匹配的打字脚本

如何提取密钥及其对应的属性类型,以供在新类型中使用?

Angular 17子路由

限制返回联合的TS函数的返回类型

Vue3 Uncaught SyntaxError:每当我重新加载页面时,浏览器控制台中会出现无效或意外的令牌

React router 6(数据路由)使用数据重定向

是否有可能避免此泛型函数体中的类型断言?

复选框Angular 在Ngfor中的其他块中重复

如何使这种一对一关系在旧表上起作用?

界面中数组中的混合类型导致打字错误

基于未定义属性的条件属性

在单独的组件中定义React Router路由

将类型脚本函数返回类型提取到VSCode中的接口

我可以使用JsDocs来澄清Typescript实用程序类型吗?

如何将对象的字符串文字属性用作同一对象中的键类型

TypeScript:方法获胜';t接受较窄类型作为参数

对于通过 Axios 获取的数据数组,属性map在类型never上不存在

React router - 如何处理嵌套路由?