Home > Software engineering >  ngOnInit() not being invoked - even first time running the Ionic app
ngOnInit() not being invoked - even first time running the Ionic app

Time:09-26

For an Ionic App that has implemented OnInit why is ngInit() not invoked? It is not happening even the first time the app/window is opened:

export class AudioRecorderComponent implements OnInit, OnDestroy {
   ...
  async ngOnInit() {
    console.log('ngOnInit()')  // never printed 
   ...

}

Is there a different way to get logic to be executed when creating an Ionic component?

CodePudding user response:

While in theory ngOnInit should work, try using viewWillEnter instead.

https://ionicframework.com/docs/angular/lifecycle

export class AudioRecorderComponent implements viewWillEnter {

 ionViewWillEnter(): void {

     console.log('view will enter');
 }

}

CodePudding user response:

This was due to the GoogleVoice extension. After disabling the extension the ngOnInit() proceeded correctly

  • Related