raj raj - 1 year ago 136
AngularJS Question

Ionic life-cycle not firing

I have an

Ionic 2
app which was working perfectly fine. I updated the ionic app from
. From then onwards I am facing an issue with ionic life-cycle event
. 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
variable is not defined before the html is loaded. I tried
and it works fine.
was working before I updated
and most examples online mentions the above method only. What happened now, what changed ?

raj raj
Answer Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download