angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

angular-universal support

Open hheexx opened this issue 10 years ago • 17 comments

Currently plugin can't be used with angular-universal without having completely separate entry points for server and browser because you are touching the DOM just by inclusion of your plugin.

ReferenceError: window is not defined at Object. (C:\Users\hexbo\Documents\cx_public\node_modules\angular2-google-maps\core\utils\browser-globals.js:11:82)

Can you delay any initialization (touching the DOM) until I call some function? Maybe calling AgmCoreModule.forRoot() shoud initialize the maps?

hheexx avatar Sep 20 '16 18:09 hheexx

Maybe @gdi2290 can help here. I have no idea if this is possible.

sebholstein avatar Sep 20 '16 18:09 sebholstein

@SebastianM Great work with PR #709! Going from your last comment in that PR, this issue can be closed?

Or is there perhaps a need for more testing?

Koslun avatar Oct 21 '16 19:10 Koslun

@Koslun thx! The initialization is now delayed. But I haven't tested it yet with angular universal.

sebholstein avatar Oct 21 '16 19:10 sebholstein

Angular2 universal does not work - Server crash - TypeError: this._elem.nativeElement.querySelector is not a function when try to load page where google map is from universal.

Tomorrow I try to use some conditions isBrowser or isNode to prevent render it by server, hope it will work.

inzerceubytovani avatar Dec 03 '16 20:12 inzerceubytovani

Ok I fix it with *ngIf="isBrowser()" on sebm-google-map component. So it works with universal, of course only on client side but I think this is not problem - you don't need to return map from server.

inzerceubytovani avatar Dec 04 '16 19:12 inzerceubytovani

I'm getting this error when using yeoman aspnetcore-spa generator to create a project with version 2.4.5 of angular.

Exception: Call to Node module failed with error: TypeError: this._elem.nativeElement.querySelector is not a function at SebmGoogleMap.ngOnInit (C:\Users\rtunis\Desktop\gogogo\ClientApp\dist\main-server.js:2139:50)

What is really strange is sometimes the map will load with the marker and everything but then when I refresh the page it just throws that exception again.

tuneis avatar Feb 06 '17 22:02 tuneis

querySelector isn't a method on the fake json dom

PatrickJS avatar Feb 15 '17 15:02 PatrickJS

Hi guys,

I'm not getting any error, but the map is still not shown. I'm doing the trick with isBrowser to render it only on the client. When inspecting the element has some children appended, but not visible.

viktorstaikov avatar Apr 28 '17 13:04 viktorstaikov

Hello, how can I solve the problem TypeError: this._elem.nativeElement.querySelector is not a function when try to load page where google map

paul-plaza avatar May 05 '17 15:05 paul-plaza

@paulPlaza You should use a *ngIf isBrowser, as this should only be ran on serverside. This will eliminate it from running on node and resulting in the error you described.

ItsMeDelanoDev avatar May 17 '17 13:05 ItsMeDelanoDev

@dneeleman, Can you please let me know what content need to be inside the isBrowser() in Typescript.

gouthamsaie avatar Jun 27 '17 07:06 gouthamsaie

@SebastianM , Whenever page loads with map i am not getting any error. But when i reload the page manually it throws as below:

this._elem.nativeElement.querySelectorAll is not a function at SebmGoogleMap.ngOnInit Please suggest me the solution to overcome this.

gouthamsaie avatar Jun 27 '17 07:06 gouthamsaie

@gouthamsaie depending on your use-case, a temporary workaround might be to load another page on the server whenever an affected page loads. Such as a page with just a loading indicator.

Can do this by using a canActivate guard which checks if the application is on the browser or server.

Doing this myself for pages which require authentication.

Koslun avatar Jun 27 '17 17:06 Koslun

@Koslun thank you so much for your response. It is only the work around. Cant we have the permanent solution and why it is occuring. If you know please let me know. Anyways appreciate your reply.

gouthamsaie avatar Jun 27 '17 17:06 gouthamsaie

I have implemented this library also in our Angular Universal project. We use a ngIf with isBrowser with platformID. But our problem is that the component will load with a blue rectangle, and only on hover/click on page the component loads the component and shows the correct Google Map.

Anyone encountered the same issue and solved this?

ItsMeDelanoDev avatar Jun 28 '17 06:06 ItsMeDelanoDev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 13 '18 23:11 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Feb 12 '19 01:02 stale[bot]