【发布时间】:2018-05-21 01:31:02
【问题描述】:
我在使用 Angular@5.1.0 时遇到了 AOT 构建问题。
错误是:
ERROR in Error during template compile of 'AppModule'
Function calls are not supported in decorators but 'FeatureModule' was called.
feature.module.ts
@NgModule({
imports: [
BrowserModule,
RouterModule.forRoot([])
],
declarations: [
...
],
exports: [
...
]
})
export class FeatureModule{
static forRoot(items:any[]): ModuleWithProviders {
const routes:Routes = items.map(t=> {
return { path: t.name, component: t.component };
});
return {
ngModule: FeatureModule,
providers: [
provideRoutes(routes)
]
}
}
}
这可以在非 aot 构建中成功编译。这似乎只是 AOT 构建的问题。
为什么会发生这个错误?
【问题讨论】:
-
这不会解决您的问题,但可能会让您更接近解决问题。 Angular 5.1 今天与 CLI 1.6 一起发布。已解决的问题之一是
Improved decorator error messages。也许尝试升级到最新版本,看看你是否能找到解决这个问题的方法。很抱歉没有提供更多帮助。 blog.angular.io/angular-5-1-more-now-available-27d372f5eb4e -
谢谢,感谢您的建议。我将尝试运行 CLI 1.6 以查看错误是否提供更多信息。
-
最新的@angular/cli中仍然存在错误。
-
您是否尝试删除
var routes - data并使用providers: [provideRoutes(data)]? -
在
Feature模块中你写了imports: [ RouterModule.forRoot() ],不应该是forRoot([])吗?可以设置复制吗?