我有一堆模塊,它們在運行時根據JSON文件的內容設置其路由(這意味着我有在這裏使用函數,除非我想打破我以前的邏輯)。我有一個數據解析成一個Routes
對象的函數,然後返回它:Angular 2:不支持函數調用
export function getRoutes(): Routes {
let routes: Routes = [
//default component
{
path: '',
component: AComponent
}
];
for(let module of APP_CONFIG.modules){
routes.push({
path: module.path,
loadChildren: module.modulePath
})
}
return routes;
}
然後我只需撥打我module
功能:
@NgModule({
declarations: [
//[...]
],
imports: [
//[...]
RouterModule.forRoot(getRoutes())
],
providers: [
//[...]
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
然而,我的項目(這是產生由角-CLI)不會建:
ERROR in Error encountered resolving symbol values statically. Calling function 'getRoutes', function calls are not supported. Consider replacing the function or lambda with a reference to an exported function
我隨後在錯誤消息中的指令,並且它內置一次。然後它繼續用同樣的信息一遍又一遍地重複故事。
所以我想我的問題是:我該如何解決這個愚蠢的問題?
你找到一個解決方案對此? – adamdport
沒有。我仍然在搜尋...... :( –