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建設。 –