Loading Google Maps SDK Dynamically


I’m working with google maps Javascript SDK,
I want to load the maps only when the user have the internet connection, I’ve done with the network thing but I only want to load the script when the internet is detected.
Can anyone please tell me how to achieve this by removing the script from index file and dynamically adding it in the TS file?

PS: I’m too close but getting this error: ReferenceError: google is not defined

Please help!


this error cause because you dont declare google variable in your ts file
write down his line above the @components
declare var google;