【发布时间】:2017-07-14 15:06:20
【问题描述】:
我一直在尝试使用带有 @angualar/compiler-cli 的 AOT 编译我的 Angular 应用程序,但我在编译过程中遇到了一个我无法解决的错误。错误状态:
Error encountered resolving symbol values statically.
Calling function 'PanelModule', function calls are not supported.
Consider replacing the function or lambda with a reference to an exported function.
我有我的主要AppModule 和另一个名为PanelModule 的模块。
在 PanelModule 我有一个 forRoot 方法,我从 AppModule 调用它,如下所示:
app.module.ts / AppModule
@NgModule( {
imports: [
BrowserModule,
routing,
PanelModule.forRoot(), <----------- If not present it compiles OK
],
declarations: [
AppComponent,
LoginView,
WorkbenchView,
ErrorView,
NotFoundErrorView,
DashboardView,
BackgroundVideoComponent
],
providers: [
{
provide: APP_BASE_HREF,
useValue: URL_BASE
},
CARBON_PROVIDERS,
CARBON_SERVICES_PROVIDERS,
appRoutingProviders,
Title,
],
bootstrap: [ AppComponent ],
} )
export class AppModule {}
panel.module.ts / PanelModule
@NgModule( {
imports: [
CommonModule,
RouterModule,
SemanticModule,
DirectivesModule,
FormsModule
],
declarations: [
HeaderComponent,
...
PaginatorComponent,
],
exports: [
HeaderComponent,
...
PaginatorComponent,
],
providers: []
} )
export class PanelModule {
static forRoot():ModuleWithProviders {
return {
ngModule: PanelModule,
providers: [ HeaderService, SidebarService, RouterService, MyAppsSidebarService, ErrorsAreaService ]
};
}
}
如您所见,PanelModule 上没有 lambda 函数。
我还看到你在 forRoot 中只能有一个 return 语句和一个 return 语句,但这不是我的情况。
我不知道发生了什么。
【问题讨论】:
-
发生了什么事?为什么要写静态函数?
-
因为这就是 Angular 建议创建 forRoot 的方式。 angular.io/docs/ts/latest/guide/ngmodule.html#!#core-for-root
-
您是否已将元数据文件与 .d.ts 文件一起发布?
-
@pixelbits 不。我怎么做?不知道我必须这样做。
-
在 tsconfig 的编译器选项中,声明:true 和 AOT 设置中 --> skipMetadataEmit: false。将它们与您的 js 文件一起部署
标签: angular angular2-aot