【问题标题】:ngrx effect class as injected services as undefinedngrx 效果类作为注入服务未定义
【发布时间】:2021-08-30 08:58:21
【问题描述】:

我在下面定义了一个ngrx效果

@Injectable()
export class AmazingEffects {

createTodos$ = createEffect(this.actions$.pipe(
ofType(CREATE_TASK)
    .map(() => {
        console.log('called');
            return { type: 'OTHER'};
})));

constructor(private readonly actions$: Action) {
}
}

由于某种原因 this.actions$ 未定义,我花了 2 天时间弄清楚,还有其他人遇到过这种问题吗?

【问题讨论】:

    标签: ngrx-store angular12


    【解决方案1】:

    我也有同样的问题,我也花了 2 天时间解决!

    {
      "compileOnSave": false,
      "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "module": "es2020",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "target": "esnext",
        "typeRoots": [
          "node_modules/@types"
        ],
        "lib": [
          "es2018",
          "dom"
        ]
      }
    }
    

    {
      "compileOnSave": false,
      "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "noImplicitOverride": true,
        "noPropertyAccessFromIndexSignature": true,
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true,
        "sourceMap": true,
        "declaration": false,
        "downlevelIteration": true,
        "experimentalDecorators": true,
        "moduleResolution": "node",
        "importHelpers": true,
        "target": "es2017",
        "module": "es2020",
        "lib": [
          "es2020",
          "dom"
        ]
      },
      "angularCompilerOptions": {
        "enableI18nLegacyMessageIdFormat": false,
        "strictInjectionParameters": true,
        "strictInputAccessModifiers": true,
        "strictTemplates": true
      }
    }
    

    我更新 tsconfig.json,设置 Strict 模式并修复所有错误;然后好了。

    【讨论】:

    • 谢谢...我会试试这个..我只是将我所有的效果定义移到了构造器中,这解决了问题..
    猜你喜欢
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-08
    • 1970-01-01
    • 2017-08-14
    • 1970-01-01
    相关资源
    最近更新 更多