小编Dav*_*rez的帖子

NgRx:如何在元减速器中使用服务?

我使用自定义中间件 ( 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)

dependency-injection ionic-framework ngrx angular ionic4

6
推荐指数
1
解决办法
3279
查看次数

require 和 module.exports : TypeError: X is not a function

文件结构:

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.js

server
??? 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)

javascript export require node.js

3
推荐指数
1
解决办法
2324
查看次数