ngrx存储中的“ TypeError:无法读取未定义的属性'release'的定义”,仅在生产版本中才带有角度

Fab*_*ink 5 typescript ngrx angular ngrx-store

我有一个问题,但只有在运行时进行生产构建之后。现在,我不确定这是错误还是执行错误。我收到错误信息““ 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;
Run Code Online (Sandbox Code Playgroud)

减速器中的index.ts

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');
Run Code Online (Sandbox Code Playgroud)

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
);
Run Code Online (Sandbox Code Playgroud)

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 {}
Run Code Online (Sandbox Code Playgroud)

帮助将不胜感激。谢谢

fro*_*sty 12

当我从桶文件导入文件时使用 NgRx 时,我遇到了同样的错误。

当您位于状态功能内部时,如果您位于从桶index.ts文件导入其中一个导出的文件中,则可能会出现此错误。在功能文件夹内部导入时,您应该从相对路径导入。只有功能文件夹之外的文件才应该使用桶文件来导入内容。

我没有明确进行导入。我的 IDE 自动完成了。搞了半天才搞明白。


Fab*_*ink 0

我得到了它。在这种情况下,“this”陈述是错误的。

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(
  getCompleteAccountState,
  fromReducer.getAccountLoading
);
export const getAccountLoaded = createSelector(
  getCompleteAccountState,
  fromReducer.getAccountLoaded
);
export const getAllAccountItems = createSelector(
  getCompleteAccountState,
  fromReducer.getAccountItems
)
Run Code Online (Sandbox Code Playgroud)

作品。谢谢大家。

干杯