提问人:user2554457 提问时间:11/5/2023 最后编辑:user2554457 更新时间:11/9/2023 访问量:59
延迟加载模块无法加载程序
lazy loading of my module fails program loading
问:
我正在尝试动态加载一个模块(取决于后端应用程序中的算法数量)。angular 应用程序会编译,但一旦我动态添加路由,就不会加载。 如果我静态(硬编码)添加它们,它们加载正常。
提前致谢! 相关代码片段如下:
lab-routing.module.ts:
export const MLRoutes: Routes = [];
export const NormRoutes: Routes = [];
export const LAB_ROUTES: Routes = [{
path: '',
component: LabComponent,
children: [
{
path: 'Dashboard',
component: LabDashboardComponent,
},
{
path: '',
redirectTo: 'Dashboard',
pathMatch: 'full',
},
{
path: '**',
component: NotFoundComponent,
},
],
}];
lab-menu.ts:
export function insert_ml(algo: string): void {
ML_ITEMS.push({
title: algo,
icon: 'keypad-outline',
children: [
{
title: 'Datasets',
icon: 'activity-outline',
link: `/lab/${algo}/dataset`,
},
{
title: 'Results',
icon: 'bar-chart',
link: `/lab/${algo}/results`,
},
],
});
MLRoutes.push({
path: algo,
loadChildren: () => import('./ml-algo/ml-algo.module').then(m => m.MLAlgoModule),
});
}
lab-dashboard.component.ts:
public refresh() {
this.http.get('http://localhost:5000/refresh').subscribe(
data => {
if (data['success']) {
data['ml_algos'].forEach(algo => insert_ml(algo));
data['norm_algos'] .forEach(algo => insert_norm(algo));
build_menu();
}
},
);
}
ml-algo-routing.module.ts:
const routes: Routes = [{
path: '',
component: MLAlgoComponent,
children: [
{
path: 'dataset',
component: MLDatasetComponent,
},
{
path: 'results',
component: MLGraphsComponent,
},
],
}];
编辑:我是否错过了代码的重要部分?我似乎再也得不到答案了,我被困住了。
答:
评论