raj raj - 15 days ago 5
AngularJS Question

Ionic life-cycle not firing

I have an

Ionic 2
app which was working perfectly fine. I updated the ionic app from
rc-0
to
rc-2
. From then onwards I am facing an issue with ionic life-cycle event
ionViewDidLoad
. I have a signup form.

import {Validators, FormBuilder, FormGroup , AbstractControl } from '@angular/forms';
export class Signup {
form: FormGroup;
constructor( formBuilder: FormBuilder) { }
ionViewDidLoad() {
this.form = this.formBuilder.group({
name: ['', Validators.required],
email: ['', CustomValidator.emailValidator],
password: ['', Validators.compose([Validators.minLength(8),Validators.required])],
password_confirmation: ['', Validators.compose([Validators.minLength(8),Validators.required])]
} }
}


And in my html page I have,

<form [formGroup]="form" (ngSubmit)="signup()">


But when the page loads , I get an exception in my web-console

EXCEPTION: Error in ./Signup class Signup - inline template:9:8 caused by: formGroup expects a FormGroup instance. Please pass one in.


I believe the
form
variable is not defined before the html is loaded. I tried
ngOnInit
and it works fine.
ionViewDidLoad
was working before I updated
Ionic
and most examples online mentions the above method only. What happened now, what changed ?

raj raj
Answer

There has been a breaking change in RC2 . As per new change ,

ionViewDidLoad, means that everything has been already loaded! including children. So if you template uses items and it undefined.

We can use the new ionViewWillLoad

ionViewWillLoad() {
    this.form = this.formBuilder.group();
}
Comments