angular - 在 Angular 中动态加载组件
问题描述
我目前正在开发一个应用程序,它使用角垫表显示一个表格。我希望动态添加每个单元格的内容。所以在我的 html 代码中,我在单元格区域中添加了一个锚元素。一般来说,我一直遵循文档中的描述(https://angular.io/guide/dynamic-component-loader)。只是,因为我有多个模板,所以我使用的是 ViewChildren 而不是 ViewChild。所以我必须订阅 ViewChildren 的查询列表,以便在添加后得到通知。初始化列表后,我想动态加载我实际想要的组件。如https://blog.angularindepth.com/everything-you-need-to-know-about-the-expressionchangedafterithasbeencheckederror-error-e3fd9ce7dbb4中所述这会导致 ExpressionChangedAfterItHasBeenCheckedErrorerror,因为我在订阅调用中更明确地将组件加载到 on change 挂钩中。我可以使用文章中描述的解决方法来解决这个问题,比如调用detectChanges(),但这并不能解决一般设置的问题,这让我感觉不对。有没有预期的方法来处理这个问题?我用我想要实现的简化版本创建了这个 stackblitz https://stackblitz.com/edit/angular-gitter-mc3xdi。它的构建类似于文档https://stackblitz.com/angular/eaaeaqnnaqxg的示例
解决方案
推荐阅读
- html - Chrome css 过渡:带有过滤器的文本消失
- telerik - Sitefinity 11无法在前端小部件控件的回发中获取下拉选择值
- angular - TypeScript this.X 不是函数
- javascript - Bootstrap 4轮播:使活动幻灯片左右两侧的幻灯片可见
- java - enum of Color Codes
- sql - 连接多个表,更好的方法 RDBMS
- python - Using powershell as Admin in python
- c# - Mono 在 Unity3d 中缺少 X509CertificateCollection ClientCertificates,有没有办法将它添加到库或资产中?
- python - python脚本转换后变量错误。他们属于皈依的那一刻
- c# - ListView 进入列表