angular - 无法在 Angular 中编辑动态组件
问题描述
我正在以通常的方式创建一个动态组件,如下所示。
const formRowFactory = this.resolver.resolveComponentFactory(FormRowComponent);
const { instance: formRowComponent } = this.newComponents.createComponent(formRowFactory);
formRowComponent.name = categoryName;
我将它的索引存储在别处,以便检索组件
const component = this.newComponents.get(index);
然后我想编辑名称,但我做不到。它不允许我访问该实例,或者没有更改它的功能。
你是怎么做到的?顺便说一句,在 Angular 中编辑内容子项非常容易。为什么对动态的如此苛刻?
解决方案
我相信这是因为当您写信时,this.newComponents.get(index)
您会收到ViewRef而不是ComponentRef。我使用动态创建的组件引用维护一个单独的数组,以便以后访问它们。
推荐阅读
- mysql - Rails:将外键添加到多列的主键
- javascript - 如何从 CSS 获取链接文本到字符串对象?
- sql - 如何在不破坏参照完整性 SQL Server 的情况下将来自不同 tbls 的地址收集到一个中
- java - 如何在 Lubuntu 中使用 PC NAME 永久挂载 Windows 共享文件夹?
- python-3.x - 针对单个问题的重复插入请求
- menu - 如何在一个 Menu::widget 中添加多个 Yii2 submenuTemplate?
- data-structures - 解决此问题的最佳方法是什么?
- asp.net - 我想从 ASP.NET 中的表中获取外键数据
- mysql - 使用 Visual Studio 或 Visual Basic 在 xampp 中更新 MySQL 数据库
- html - 垂直对齐等宽字体中的html实体字符?