AngularHybrid:loadchildren和升级组件出错

d6kp6zgx  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(225)

我正在尝试创建一个混合应用程序(angular+angularjs),其中包含延迟加载的angular模块。
当我尝试使用包含升级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
没有延迟加载的一个:https://stackblitz.com/edit/angular-3aogfs

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题