我使用自定义中间件 ( meta-reducer ) 打印我的ngrx-store每次操作被分配。我直接在里面写了我的中间件app.module.ts(我应该把它放在哪里?):
app.module.ts
// ...imports
// ...
// FIXME:
/**
* console.log action and state(before action) each time an action is dipatched
* @param reducer reducer
*/
export function debug(reducer: ActionReducer<AppState, Actions>): ActionReducer<AppState, Actions> {
const logger = new LoggerService(); ////////////// ERROR \\\\\\\\\\\\\\
return (state, action) => {
logger.storeInfo('ACTION', action);
logger.storeInfo('STATE', state);
return reducer(state, action);
};
}
export const metaReducers: MetaReducer<any>[] = [
debug,
];
@NgModule({
declarations: [AppComponent, LoggerServiceComponent],
entryComponents: [],
imports: [ …Run Code Online (Sandbox Code Playgroud) server
??? controllers
? ??? locationsController.js
? ??? mainController.js
? ??? utilisateursController.js
??? models
? ??? Locations.js
? ??? Utilisateurs.js
| ??? ...
??? routes.js
??? server.js
Run Code Online (Sandbox Code Playgroud)
在mainController我有一个isValid检查字符串的函数中,我把它放在那里,因为我想从utilisateursController.js和访问它locationsController.js。我将其导出如下:
mainController.jsserver
??? controllers
? ??? locationsController.js
? ??? mainController.js
? ??? utilisateursController.js
??? models
? ??? Locations.js
? ??? Utilisateurs.js
| ??? ...
??? routes.js
??? server.js
Run Code Online (Sandbox Code Playgroud)
我可以isValid从访问该函数utilisateursController.js,但是当我尝试从 执行相同操作时locationsController.js,出现以下错误:
(node:6461) UnhandledPromiseRejectionWarning: TypeError: mc.isValid is not …Run Code Online (Sandbox Code Playgroud)