Ionic v.4 really get the data from provider

Hi,
In constructor :
I get a free id with an API from a provider in my code.
this.idContact = myProfil.getUserId();
the console.log of my provider tells me that the idContact is known
[ng] [console.log]: "Current user : 8"

then
in ionViewWillEnter
I want to get the data for this user with another API request

  ionViewWillEnter() {
    console.log('ionViewDidEnter idContact : ' + this.idContact);
    this.getUserData(this.idContact);
  }

But finally, this.idContact is undefined !! Whereas the log just above told me it had a value ?!
[ng] [console.log]: "ionViewDidEnter idContact : undefined"

what’s wrong in this code according to you ?
(maybe should I use promises ? I could need help to do it…)

(Note : there is no ‘ionic-v4’ category to post in this forum. I posted in ionic-v3)
Thanks :wink:

I would recommend adding the following to tsconfig.json:

"noImplicitAny": true,
"strictNullChecks": true,
"strictPropertyInitialization": true

Replace all instances of any that you have written in your code with actual types. This should allow your IDE to guide you through the next several questions you will have here.

All controller properties that are accessed from a template need to be valid at all times. strictPropertyInitialization tells tsc to enforce that.

OK thank you, I understand what you mean there :wink:
pretty good advice !