我有一个动态添加到父组件的子组件。 这是我的父母html:
<button (click)="addHtml()">add html</button>
<div #list></div>
这是我的父组件
export class LogComponent {
@ViewChild('list', {read: ViewContainerRef}) list: ViewContainerRef;
private addHtml(log: Log) {
var cf = this.resolver.resolveComponentFactory(ItemComponent)
let res = this.list.createComponent(cf)
}
}
但子组件是在父html的末尾添加的,而不是#list元素,为什么? 提前谢谢