我有一个问题,但只有在生产构建运行时。现在我不确定这是一个bug还是我做错了。我得到错误““TypeError:无法读取控制台(浏览器)中未定义的”.”的属性'release',如果我使用ngrx加载以下功能模块(在运行时):
import { AccountDto } from '../../../dto';
import * as fromAccountActions from '../actions/account.actions';
export interface AccountState {
loading: boolean;
loaded: boolean;
accountItems: AccountDto[];
}
export const initialState: AccountState = {
loading: false,
loaded: false,
accountItems: []
};
export function accountReducer(
state = initialState,
action: fromAccountActions.AccountActions
): AccountState {
switch (action.type) {
case fromAccountActions.LOAD_ACCOUNT: {
// console.log(action.type);
return { ...state, loading: true };
}
case fromAccountActions.LOAD_ACCOUNT_FINISHED: {
console.log('Finished: ' + action.payload);
return {
...state,
loading: false,
loaded: true,
accountItems: action.payload
};
}
case fromAccountActions.LOAD_ACCOUNT_FAILED: {
return {
...state,
loading: false,
loaded: false,
accountItems: []
};
}
default:
return state;
}
}
export const getAccountItems = (state: AccountState) => state.accountItems;
export const getAccountLoading = (state: AccountState) => state.loading;
export const getAccountLoaded = (state: AccountState) => state.loaded;
减速器中的指数t
import * as fromReducer from './account.reducers';
import { ActionReducerMap } from '@ngrx/store';
import { createFeatureSelector } from '@ngrx/store';
export interface AccountState {
account: fromReducer.AccountState;
}
export const reducers: ActionReducerMap<AccountState> = {
account: fromReducer.accountReducer
};
export const getAccountState = createFeatureSelector<AccountState>('account');
account.selectors.ts
import { createSelector } from '@ngrx/store';
import * as fromReducer from '../reducers/account.reducers';
import * as fromFeature from '../reducers';
export const getCompleteAccountState = createSelector(
fromFeature.getAccountState,
(state: fromFeature.AccountState) => state.account
);
export const getAccountLoading = createSelector(
this.getCompleteAccountState,
fromReducer.getAccountLoading
);
export const getAccountLoaded = createSelector(
this.getCompleteAccountState,
fromReducer.getAccountLoaded
);
export const getAllAccountItems = createSelector(
this.getCompleteAccountState,
fromReducer.getAccountItems
);
account.module.ts
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { ThirdPartyModule } from '../thirdParty/thirdParty.module';
import { SharedModule } from './../shared/shared.module';
import { AccountListComponent } from './account-list/account-list.component';
import { AccountRoutesModule } from './account.routes';
import { StoreModule } from '@ngrx/store';
import { EffectsModule } from '@ngrx/effects';
import { reducers, AccountEffects } from 'app/+account/store';
@NgModule({
imports: [
CommonModule,
FormsModule,
SharedModule,
AccountRoutesModule,
ThirdPartyModule,
TranslateModule,
StoreModule.forFeature('account', reducers),
EffectsModule.forFeature([AccountEffects])
],
declarations: [AccountListComponent],
providers: [],
exports: []
})
export class AccountModule {}
如果你能帮忙的话,我会非常感激的。谢谢
3条答案
按热度按时间jvlzgdj91#
我得到了这个相同的错误时,使用NgRx时,我正在导入文件形式桶文件。
当你在一个状态特征中时,如果你在一个从barrel
index.ts
文件导入其中一个导出的文件中,你可能会得到这个错误。在要素文件夹内导入时,应从相对路径导入。只有特征文件夹之外的文件才应该使用桶文件来导入内容。我没有明确地做导入。我的IDE自动完成了。我花了半天才弄明白。
yuvru6vn2#
我明白了。在那种情况下“这个”的说法是错误的。
很好。谢谢大家。
干杯
pxy2qtax3#
您在导入中有额外的
+
符号。在
account.module.ts
中:试着去掉它,应该能解决问题