假设我有一个像这样的组件
@Component({
selector: 'app-root',
styleUrls: ['./app.component.css'],
template: `
<div>
<div class='parent' #parent></div>
<div class='child' #child></div>
</div>
`
})
export class AppComponent implements OnInit, AfterContentInit {
@ViewChild('parent', { read: ViewContainerRef }) parent: ViewContainerRef;
@ViewChild('child', { read: TemplateRef }) child: TemplateRef<any>;
constructor(private container: ViewContainerRef) {
}
ngOnInit() {
}
}
我想将子div放在父div中,但是当我像这样使用时,我仍然无法实现它
ngAfterContentInit() {
this.parent.createEmbeddedView(this.child)
}