Closed MapleYe closed 7 years ago
Hi, the library currently doesn't support server side rendering. I'm not familiar with the server side rendering so if you have a sample repository that i could use to fix the issue, that would be great.
A PR would also be appreciated :).
You might be able to solve this issue on your own by extending WebStorage library and useClass. Instead of using window.localStorage(since it doesn't exist) you'd have to use the server side storage capabilities whatever they are(IndexDb, WebDB, etc)
Thanks misha130. I'll give them a try.
For others coming later, I was able to workaround this by simple wrapping code that accessed the webstorage with:
import { Inject, PLATFORM_ID } from "@angular/core";
import { isPlatformBrowser } from "@angular/common";
// Service definition goes here
constructor(
private localStorage: LocalStorageService,
@Inject(PLATFORM_ID) private platformId: Object) {
if (isPlatformBrowser(platformId)) {
// Code that uses localStorage
}
}
@lotsabackscatter this will only work with injected services...
what about the decorators ? ;)
Doing an online shop project. Decorate cartline array with @LocalStorage(). The shopping cart works perfectly on the client side. But it failed (cannot continue loading the website) when I tried server rendering. So is it possible to get the item count when the app is loaded first from the server?