SortableJS / ngx-sortablejs

Angular 2+ binding to SortableJS. Previously known as angular-sortablejs
https://sortablejs.github.io/ngx-sortablejs/
MIT License
466 stars 160 forks source link

Angular Universal: SSR - window is not defined #184

Open nncl opened 4 years ago

nncl commented 4 years ago

Hello,

I'm using ngx-sortablejs in my application, and works as expected, the only problem is that this same application uses Angular Universal to server side rendering, and the following error is returned from the server:

ReferenceError: window is not defined
    at new Sortable (/var/www/app/dist/server/main.js:121650:73)
    at Function.Sortable.create (/var/www/app/dist/server/main.js:123098:12)
    at Timeout.<anonymous> (/var/www/app/dist/server/main.js:135544:87)
    at ZoneDelegate.invokeTask (/var/www/app/dist/server.js:578:31)
    at Zone.runTask (/var/www/app/dist/server.js:350:47)
    at ZoneTask.invokeTask (/var/www/app/dist/server.js:653:34)
    at Timeout.ZoneTask.invoke (/var/www/app/dist/server.js:642:48)
    at Timeout.timer [as _onTimeout] (/var/www/app/dist/server.js:2387:29)
    at listOnTimeout (internal/timers.js:531:17)
    at processTimers (internal/timers.js:475:7)

Is there anything to do in order to avoid its load on the server side? Or is it something that the original library should - maybe - do?

By now I'm handling this problem with isPlatformBrowser and not rendering it through *ngIf, but it doesn't look nice.

Thanks for your great work.

lares83 commented 4 years ago

Have the same issue. any update about this bug? it used to works fine

carbonhe commented 3 years ago

@nncl https://github.com/angular/universal/issues/1523#issuecomment-600320144 please check this, I think it's helpful.