我正在尝试使用延迟加载的 Angular 模块创建一个混合应用程序(Angular + AngularJS)。
当我尝试使用包含升级的 AngularJS 组件的组件延迟加载模块时,出现以下错误:
路线
const appRoutes: Routes = [
{
path: 'toto',
loadChildren: () => import('./toto/toto.module').then(module => module.TotoModule)
}
];
错误
Error: Uncaught (in promise): Error: Trying to get the AngularJS injector before it being set.
Error: Trying to get the AngularJS injector before it being set.
at injectorFactory (upgrade-static.umd.js:1266)
at _callFactory (ng_module.ts:201)
at _createProviderInstance (ng_module.ts:154)
at resolveNgModuleDep (ng_module.ts:110)
at NgModuleRef_.get (refs.ts:423)
at Object.resolveDep (provider.ts:424)
at Injector_.get (refs.ts:372)
at new UpgradeHelper (upgrade-static.umd.js:1491)
at new UpgradeComponent (upgrade-static.umd.js:1802)
at new MyExampleDirective (VM270 toto.module.ts:13)
at resolvePromise (zone.js:1255)
at resolvePromise (zone.js:1209)
at eval (zone.js:1321)
at ZoneDelegate.invokeTask (zone.js:434)
at Object.onInvokeTask (ng_zone.ts:390)
at ZoneDelegate.invokeTask (zone.js:433)
at Zone.runTask (zone.js:205)
at drainMicroTaskQueue (zone.js:620)
at ZoneTask.invokeTask [as invoke] (zone.js:520)
at invokeTask (zone.js:1656)
当我在 AppModule 中导入模块并执行以下路线时,它工作正常:
const appRoutes: Routes = [
{
path: 'toto',
children: TotoRoutes
}
];
我创建了 2 个 stackblitz :
使用延迟加载的那个,触发错误: https ://stackblitz.com/edit/angular-uye3ld