我目前正在考虑在运行时加载一个组件,并在谷歌搜索之后来到这个页面。
我想知道是否可以在app.component.ts中对此进行编码以从HERE加载组件。
例如:
import { Component, OnInit, Directive, ViewContainerRef } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(public viewContainerRef: ViewContainerRef) { }
ngOnInit() {
// CODE TO LOAD THE COMPONENT HERE
}
}
可以使用 OnInit 或 ngAfterViewInit 完成吗?如果是这样的话?