0
请帮忙。我试图延迟加载一个模块,具体取决于设备类型,但是得到一个错误:“ERROR in Error遇到静态解析符号值。只能初始化变量和常量,因为模板编译器需要此变量的值。 ”Angular 4 - 在路由中静态解析符号值时出错
下面是代码:
//routing.ts
export declare var MobileDetect: any;
export var devicePath;
export var deviceType = new MobileDetect(window.navigator.userAgent);
if (deviceType.phone() != null) {
devicePath = 'app/mobile/mobile.module#MobileModule';
}
else{
devicePath = 'app/desktop/desktop.module#DesktopModule';
}
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: '', loadChildren: devicePath}
];
export const routing: ModuleWithProviders = RouterModule.forRoot(routes);
你在干什么AOT? – JEY
对不起忘了提到我在AOT建设。 –