我想从我的应用程序注销,在退出之前我想确保在此代码的帮助下使用MetaReducer
完全清除了我的应用程序ngrx存储状态
import { StoreModule, ActionReducer, MetaReducer } from '@ngrx/store';
export function logout(reducer: ActionReducer<any>): ActionReducer<any> {
return function (state, action) {
if (action.type === 'LOGOUT') {
state = undefined;
}
return reducer(state, action);
};
}
export const metaReducers: MetaReducer<any>[] = [logout];
当我在订阅ngrx商店状态之一的组件内部时,例如发票列表,所以当我从这里点击注销按钮时,在控制台
并且给出错误的行是
this.$invoice.takeWhile(() => this.isComponentAlive).subscribe(
invoice => {
this.permission = this.departmentService.getPermissionOfInvoiceCurrentDepartment(invoice.currentDepartmentId);
}
);
如果我要将代码更改为此
this.$invoice.takeWhile(() => this.isComponentAlive).subscribe(
invoice => {
if (invoice) {
this.permission = this.departmentService.getPermissionOfInvoiceCurrentDepartment(invoice.currentDepartmentId);
}
}
);
它解决了这个问题,但我有很多这样的地方,所以我想为这个一站式解决方案,任何人都可以帮助我。