【发布时间】:2019-11-13 00:53:00
【问题描述】:
我正在使用以下代码动态创建组件:
components = {}
....
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(componentClass);
const component = this.container.createComponent(componentFactory);
// Push the component so that we can keep track of which components are created
this.components[pageNumber].push(component);
现在,我正在尝试模拟多页表单行为,因此当用户单击“下一页”时,我使用 this.container.clear() 清除容器并使用新页面的组件重新填充它。
一切正常,我在每个页面上都创建了一个组件列表。但是,如果用户单击“上一页”按钮,我会陷入困境。我不确定如何使用存储在 this.components 对象中的组件重新填充容器?
我无法再次推送新组件,因为用户可以修改它们的值,重新创建它会重置所有值。
这是正确的方法,还是我应该以不同的方式研究它? 谢谢。
【问题讨论】:
标签: javascript html angular typescript angular-components