0
私のアプリケーションでは、私のレデューサーのカップルからエラーが発生した時点で問題が発生しています。私は問題の行にブレークポイントを置くので問題はないようですので少し混乱します。私が手にエラーがある:Angular4のngrxレデューサ内で未定義のエラー
app.module
//Instantiate the Angular Object
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
ChartsModule,
AgmCoreModule.forRoot({
apiKey: APP_DI_CONFIG.GOOGLE_MAPS_API_KEY
}),
StoreModule.provideStore({
reportExceptionsReducer,
reportExceptionFormDefaultsReducer,
reportExceptionsModelReducer,
reportExceptionUIReducer,
usersReducer,
usersUIReducer
}),
routing
],
.......
UserDashboardComponent.ts
import { Component, OnInit } from "@angular/core";
import { AuthenticationService } from "../../services/authentication.service";
import { UserService } from "../../services/users/user.service";
import { User } from "../../classes/User.class";
import { Store } from "@ngrx/store";
import { CHANGE_USERS_FILTERS, POPULATE_USERS } from "../../state/actions/actions";
@Component({
selector: 'user-dashboard',
moduleId: module.id,
templateUrl: '/app/views/users/users-dashboard.component.html'
})
export class UsersDashboardComponent {
protected users: Array<User>;
protected payload: Object;
protected viewState: Object = {
usersLoaded: false as boolean
};
protected activeUsersConfig: Object = {
title: 'Users',
showEdit: true as Boolean,
showDelete: true as Boolean
};
constructor(
private _userService: UserService,
private _authenticationService: AuthenticationService,
private _store: Store<any>
) {
this._store.select('usersReducer')
.subscribe((users) => {
this.users = users;
});
this._store.select('usersUIReducer')
.subscribe((payload) => {
this.payload = payload;
if(!this._authenticationService.isSuper()) {
this.payload.account = this._authenticationService.accountId
}
});
this.getUsers();
}
getUsers(): void {
this._userService.getUsers(this.payload)
.subscribe((response) => {
this._store.dispatch({ type: POPULATE_USERS, payload : {users: response.extras.Users}});
this.viewState.usersLoaded = true;
//this.payload.maxItems = response.Users.maxItems;
});
}
paginationChange(pageNum): void {
this.viewState.usersLoaded = false;
const offset = pageNum * this.payload.limit;
this._store.dispatch({ type: CHANGE_USERS_FILTERS, payload: { offset }});
this.getUsers();
}
}
と減速
import { Action } from "@ngrx/store";
import { CHANGE_USERS_FILTERS } from "../../actions/actions";
const initialState = {
account: undefined as number,
limit: 1 as number,
maxItems: 10 as number,
offset: 0 as number
};
export const usersUIReducer = (state: any = initialState, action: Action) => {
switch(action.type) {
case CHANGE_USERS_FILTERS :
return Object.assign({}, ...state,
action.payload
);
default :
return state;
}
};
:ここ
ERROR TypeError: undefined is not a function
at exports.usersUIReducer (usersUI.reducer.ts:14)
は、関連するコードです
私のngrxの実装は、他の経験豊富なユーザーが見る限り正しいですか?なぜ私はエラーが発生しているのか、文字通りどこから始めたらいいのか分からない。
おかげ
あなたはplunkrとサンプルコードでこの問題を再現することができます
あなたのような何かをする必要がありますか? – Thaadikkaaran