在动态组件加载的情况下,是否预期行为不会调用ngOnChanges生命周期钩子?只为我调用构造函数ngOnInit和ngAfterViewInit.但是根据文档,它应该在ngOnInit之前调用.
我正在加载这样的组件:
@ViewChild('place', { read: ViewContainerRef }) container: ViewContainerRef;
private componentRef: ComponentRef<MyLoggerComponent>;
constructor(private componentFactoryResolver: ComponentFactoryResolver) { }
ngAfterViewInit() {
const componentFactory: ComponentFactory<any> = this.componentFactoryResolver.resolveComponentFactory(MyLoggerComponent);
this.componentRef = this.container.createComponent(componentFactory);
this.componentRef.changeDetectorRef.detectChanges();
}
Run Code Online (Sandbox Code Playgroud)
angular ×1