我正在使用角度cli构建角度模块。在另一个项目中,我正在调用此模块。
当我运行ng serve
时,一切正常。但是当我运行ng build --prod
时,出现以下错误:
错误 ./node_modules/my-module/dist/pagination/pagination.ngfactory.js 找不到模块:错误:无法解析“分页” '/ my-web-application / node_modules / my-module / dist / pagination'
./src/app/app.module.ngfactory.js中的ERROR找不到模块:错误: 无法解析“ / my-web-application / src / app”中的“分页”
./src/app/areas/private/users/list/index.ngfactory.js模块中的ERROR 找不到:错误:无法解析“分页” '/ my-web-application / src / app / areas / private / users / list'
在我的Web应用程序中,我以这种方式加载模块
@NgModule({
...
imports: [
MyModule
],
...
bootstrap: [AppRootComponent]
})
export class AppModule { }
并以此方式调用组件模块
<pagination [data]="pagination"></pagination>
在MyModule中,这是它的配置方式
@NgModule({
declarations: [PaginationComponent],
imports: [
CommonModule,
],
exports: [PaginationComponent]
})
export class MyModule { }
该怎么做才能使其仅在ng build --prod
时崩溃?
Angular CLI: 8.3.5
Node: 10.15.0
OS: darwin x64
Angular: 8.2.7
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.5
@angular-devkit/build-angular 0.803.5
@angular-devkit/build-optimizer 0.803.5
@angular-devkit/build-webpack 0.803.5
@angular-devkit/core 8.3.5
@angular-devkit/schematics 8.3.5
@angular/cdk 8.2.0
@angular/cli 8.3.5
@angular/flex-layout 8.0.0-beta.27
@angular/material 8.2.0
@ngtools/webpack 8.3.5
@schematics/angular 8.3.5
@schematics/update 0.803.5
rxjs 6.4.0
typescript 3.5.3
webpack 4.39.2
答案 0 :(得分:0)
在MyModule中,将PaginationComponent添加到导出数组:
@NgModule({
exports: [
PaginationComponent
]
})
export class MyModule {}
修改:
也适用于:
<pagination [data]="pagination"></pagination>
确保属性pagination
在实现该代码的方法中是公共的
答案 1 :(得分:0)
您也需要在AppModule中导出MyModule模块,如下所示:
@NgModule({
...
imports: [
MyModule
],
exports: [MyModule]
...
bootstrap: [AppRootComponent]
})
export class AppModule { }