【发布时间】:2018-06-03 13:21:51
【问题描述】:
我使用ComponentFactoryResolver 动态创建组件为shown in the docs。
// create a component each time this code is run
public buildComponent() {
const factory = this.componentFactoryResolver.resolveComponentFactory(MyComponent);
const componentRef = this.viewContainerRef.createComponent(factory);
const component = componentRef.instance;
this.componentArray.push(component);
}
这很好用。每次函数运行时,都会创建一个新的MyComponent,并将其添加到提供的ViewContainerRef 位置的DOM 中。现在遵循一些用户操作,我想重新排序组件。例如,我可能想将最后创建的组件在容器中上移一个位置。这可以在 Angular 中完成吗?
public moveComponentUp(component) {
// What to do here? The method could also be passed the componentRef
}
【问题讨论】:
标签: angular