我有一个导出ParentModule的文件及其导入模块的数组
export const PARENT_MODULES = [
module1,
...
someModule,
...
moduleN
];
@NgModule({ imports: [...PARENT_MODULES] })
export class ParentModule{ }
除了一次导入(ModifiedParentModule
而不是ParentModule
)之外,我想创建与anotherModule
相同的someModule
。如果没有再次输入整个导入列表,有没有办法做到这一点?
我试过了:
export const replaceModules = module =>
module.name === someModule.name ? anotherModule.name : module;
export const MODIFIED_PARENT_MODULES = PARENT_MODULES.map(replaceModules)
@NgModule({ imports: [...MODIFIED_PARENT_MODULES ]})
export class ModifiedParentModule{ }
但是它给出了错误
ERROR in TypeError: Cannot use 'in' operator to search for 'providers' in null
at C:\app-ext\node_modules\@angular\compiler-cli\src\ngtools_impl.js:111:73
at Array.filter (native)
at _extractLazyRoutesFromStaticModule (C:\app-ext\node_modules\@angular\compiler-cli\src\ngtools_impl.js:111:29)
at includeLazyRouteAndSubRoutes (C:\app-ext\node_modules\@angular\compiler-cli\src\ngtools_impl.js:66:25)
at Array.reduce (native)
at Object.listLazyRoutesOfModule (C:\app-ext\node_modules\@angular\compiler-cli\src\ngtools_impl.js:54:36)
at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\app-ext\node_modules\@angular\compiler-cli\src\ngtools_api.js:91:39)
at AotPlugin._getLazyRoutesFromNgtools (C:\app-ext\node_modules\@ngtools\webpack\src\plugin.js:207:44)
at _donePromise.Promise.resolve.then.then.then.then.then (C:\app-ext\node_modules\@ngtools\webpack\src\plugin.js:443:24)
at process._tickCallback (internal/process/next_tick.js:103:7)
答案 0 :(得分:0)
添加导出所有必需共享模块的BaseSharedParentModule
@NgModule({
imports: [...PARENT_MODULES],
exports: [...PARENT_MODULES]
})
export class BaseSharedParentModule { }
ParentModule和ModiefiedParentModule都导入容器模块,如下所示
@NgModule({
imports: [BaseSharedParentModule],
})
export class ParentModule{ }
@NgModule({
imports: [BaseSharedParentModule],
})
export class ModifiedParentModule{ }