首页 > 解决方案 > Ngrx Store 和 Ionic 3 - 将 reducer 添加到 app.module 时未处理的 Promise 拒绝

问题描述

我有一个 ionic3 项目,我正在尝试使用 ngrx-store。我创建了一个简单的 reducer、action、model 和 app.state。当我将减速器添加到 app.module.ts时出现以下错误。减速器尚未在任何组件中使用。

Unhandled Promise rejection: Cannot read property 'schedule' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'schedule' of undefined
    at ObserveOnSubscriber.scheduleMessage (observeOn.js:93)
    at ObserveOnSubscriber._error (observeOn.js:99)
    at ObserveOnSubscriber.Subscriber.error (Subscriber.js:106)
    at ActionsSubject.Observable._trySubscribe (Observable.js:177)
    at ActionsSubject.Subject._trySubscribe (Subject.js:97)
    at ActionsSubject.Observable.subscribe (Observable.js:160)
    at ObserveOnOperator.call (observeOn.js:69)
    at AnonymousSubject.Observable.subscribe (Observable.js:157)
    at WithLatestFromOperator.call (withLatestFrom.js:69)
    at AnonymousSubject.Observable.subscribe (Observable.js:157) TypeError: Cannot read property 'schedule' of undefined
    at ObserveOnSubscriber.scheduleMessage (http://localhost:8100/build/vendor.js:55994:33)
    at ObserveOnSubscriber._error (http://localhost:8100/build/vendor.js:56000:14)
    at ObserveOnSubscriber.Subscriber.error (http://localhost:8100/build/vendor.js:20763:18)
    at ActionsSubject.Observable._trySubscribe (http://localhost:8100/build/vendor.js:331:18)
    at ActionsSubject.Subject._trySubscribe (http://localhost:8100/build/vendor.js:23279:51)
    at ActionsSubject.Observable.subscribe (http://localhost:8100/build/vendor.js:314:93)
    at ObserveOnOperator.call (http://localhost:8100/build/vendor.js:55970:23)
    at AnonymousSubject.Observable.subscribe (http://localhost:8100/build/vendor.js:311:22)
    at WithLatestFromOperator.call (http://localhost:8100/build/vendor.js:92156:23)
    at AnonymousSubject.Observable.subscribe (http://localhost:8100/build/vendor.js:311:22)

我有一个简单的减速器

import * as BudgetActions from './budget.actions'
import { BudgetCategory } from './budget.model'

    export function budgetReducer(state: BudgetCategory[] = [], action : BudgetActions.Actions) {

        switch(action.type) {
            case BudgetActions.GET_ALL_BUDGET_CATEGORIES:
                return state;
            case BudgetActions.ADD_BUDGET:
                return [...state, action.payload];
            case BudgetActions.REMOVE_BUDGET:
                //splice the budget based on the id in payload
                return state;
            case BudgetActions.STORE_ALL_BUDGET_CATEGORIES:
                state = action.payload;
                return state;
            default:
                return state;
        }
    } 

请问有什么建议可以试试吗?

让我知道代码的任何其他部分是否有助于获得一些关于建议的想法。

标签: javascriptangularionic3ngrx-store

解决方案


推荐阅读