SV Startup Lab
Jul 21, 2017 · 1 min read

The Angular docs in the Lifecycle Hooks section includes the wait a tick hack. I’m not sure why you are recommending against it? After a day of research I can’t figure out how to re-architect my simple setup anyway. Just an edit form child getting loaded into a parent and then loading the data into the form. When the fuction for loading the data is wrapped in setTimeout it works fine:

ngAfterViewInit() {
setTimeout(() => {
this.fetchMember();
});
}

Per https://angular.io/guide/lifecycle-hooks#afterview

Abide by the unidirectional data flow rule

Why does the doSomething() method wait a tick before updating comment?

Angular’s unidirectional data flow rule forbids updates to the view after it has been composed. Both of these hooks fire after the component’s view has been composed.

This is all the child component does, besides set some properties:

ngOnInit() {
this.createForm();
}

// The reactive model that is bound to the form.

createForm(): void {
this.addEditMemberForm = this.fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
mainSkillTitle: ['', Validators.required],
mainSkills: ['', Validators.required],
otherSkills: ['', Validators.required],
links: ['', Validators.required],
country: ['', Validators.required],
email: ['', Validators.required]
});
}

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade