Ionic typescript initialisation

Hi guys. I have a question regarding initialisation. So I initialised the variable of map using return in the function. And I got the error of “Cannot read property ‘nativeElement’ of undefined”. I have looked at the way typescript assigns values, and I still cannot figure out what went wrong. Can someone please explain?


mapElement comes from @ViewChild. In InitMap() you use it. Second Picture (why do you do not use editor with his formatting possiblities? pictures are imho bad readable) shows you call call InitMap(), but it’s for me not clear at which point of life cycle you call it. Maybe you call it to early.

Best Regards, anna-liebt

Hi. Thanks for replying. I think I found the problem. Yet to be solved. As this is a provider, elementRef only works in pages where html is provided. It is impossible to do direct manipulation of DOM in provider because it happens in pages


If I understood it correct above code is inside a provider. Okay, same problem. The error means whatever from whatever.NativeElement is not available. So provide it.
Fetch your map in your page and call your provider with fetched element as parameter like


Best regards, anna-liebt

One big cause of issues is that you’re using function all over the place which will break this and have it refer to the wrong thing.

Another thing is that there’s no reason to manually create a Promise.