Is it possible to identify whether the Angular2 component (here AppComponent) is fully loaded (including ViewChild) when in the ngIf template, which conditionally loads the child element.
Ref: Angular 2 @ViewChild annotation returns undefined This example is taken from the above help. Thanks kenecaswell
import {Component, ViewChild, OnInit, AfterViewInit} from 'angular2/core'; import {ControlsComponent} from './child-component-1'; import {SlideshowComponent} from './slideshow/slideshow.component'; @Component({ selector: 'app', template: ` <div *ngIf="controlsOn"> <controls ></controls> <slideshow></slideshow> </div> `, directives: [SlideshowComponent, ControlsComponent] }) export class AppComponent { @ViewChild(ControlsComponent) controls:ControlsComponent; @ViewChild(SlideshowComponent) slide:SlideshowComponent; controlsOn:boolean = false; ngOnInit() { console.log('on init', this.controls);
ngOnInit && ngAfterViewInit are launched before loading child components due to the ngIf condition
I need to determine when SlideshowComponent and ControlsComponent are loaded, and perform an action based on this.
I have a hacker solution that doesnβt work when there are several ViewChilds (which have a different type) - Using an event emitter to inform when a child is loaded.
I am posting this question because there was no right solution after several hours of research.
javascript angularjs angular angularjs-components
tymspy
source share