WestCoastProjects
WestCoastProjects

Reputation: 63062

ngOnInit() not being invoked - even first time running the Ionic app

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?

Upvotes: 1

Views: 426

Answers (2)

user796446
user796446

Reputation:

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');
 }

}

Upvotes: 1

WestCoastProjects
WestCoastProjects

Reputation: 63062

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

Upvotes: 0

Related Questions