出现该问题的原因是使用了Angular的AOT编译器,该编译器会对样式和模板进行处理,导致Webcomponent未能正确加载。为了解决这个问题,可以尝试使用以下方法:
"angularCompilerOptions": { "skipTemplateCodegen": true }
@NgModule({ ... imports: [ ... AppModuleWithoutAot, ... ], ... }) export class AppModule { }
@NgModule({ declarations: [MyWebComponent], imports: [ RouterModule.forChild([{ path: '', component: LazyComponent }]) ] }) export class LazyModule {}