You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
@gdi2290 as this has been taken off of the Beta.0 milestone, do you have a vision for when angular universal will offer localStorage support? Thank you in advance
@gdi2290 For now localStorage is not accepted in my Universal app (everything else is working) and crashes the server, is there something special to import or is it not ready yet ?
@cyrilletuzi to transfer state from the server to the client you can use a lifecycle hook in Node and the helper flags isBrowser and isNode main.browser.ts
import{isBrowser,isNode}from'angular2-universal';
@NgModule({bootstrap: [App],declarations: [App,Home],imports: [UniversalModule,// BrowserModule, HttpModule, and JsonpModule are includedFormsModule,RouterModule.forRoot([{path: '',component: Home,pathMatch: 'full'}])]})exportclassMainModule{constructor(publicappRef: ApplicationRef){// lives in your browser main modulevarkey='yourServiceWithState._state'if(UNIVERSAL_CACHE[key]){localStorage[key]=UNIVERSAL_CACHE[key]}}}
main.node.ts
import{isBrowser,isNode}from'angular2-universal';
@NgModule({bootstrap: [App],declarations: [App,Home],imports: [UniversalModule,// BrowserModule, HttpModule, and JsonpModule are includedFormsModule,RouterModule.forRoot([{path: '',component: Home,pathMatch: 'full'}])]})exportclassMainModule{constructor(publicappRef: ApplicationRef){}// lives in your node main moduleuniversalDoDehydrate(universalCache){varyourServiceWithState=this.appRef.injector.get(YourServiceWithState)varkey='yourServiceWithState._state'universalCache[key]=yourServiceWithState._state.justOneProp}}
or if you're using the same entry file then it's
import{isBrowser,isNode}from'angular2-universal';
@NgModule({bootstrap: [App],declarations: [App,Home],imports: [UniversalModule,// BrowserModule, HttpModule, and JsonpModule are includedFormsModule,RouterModule.forRoot([{path: '',component: Home,pathMatch: 'full'}])]})exportclassMainModule{constructor(publicappRef: ApplicationRef){// lives in your browser main moduleif(isBrowser){varkey='yourServiceWithState._state'if(UNIVERSAL_CACHE[key]){localStorage[key]=UNIVERSAL_CACHE[key]}}}// lives in your node main moduleuniversalDoDehydrate(universalCache){varyourServiceWithState=this.appRef.injector.get(YourServiceWithState)varkey='yourServiceWithState._state'universalCache[key]=yourServiceWithState._state.justOneProp}}
It sounds like you need some initial logic the moment before the app gets serialized, or during, so that it can decide what route to instead render, or components to show,etc ?
Is everything working or are you worried about security with this? No worries! Sorry if I'm slow to respond, I've been trying to tackle of a few things at once, it's hard to find time for everything :)
Check the implementation: just updated this repo as well as publishing 4 separate packages for cache operations both on server and browser platforms. Everything is handled via the @Cached(...) decorator on the method/loader/etc which you want it cached. Also, there's the possibility to use caching methods (has, get, set) using the caching API.
You might ask why to keep the structure so complex and consume 4 different packages? The answer is, not all the use cases depend on caching on the server platform. Furthermore, this structure allows to integrate any kind of custom caching with the server or browser platform (ex: session, api, etc).
Currently there's no documentation available for these packages, because these days I'm kinda overloaded with many different tasks/projects. I think in a week or two I'll try to provide a good documentation as well as unit tests for these packages.
However, try to have a look on this repo - about the use of CacheService and its instruments. I think it won't be difficult to understand the concepts, as I've kept the code style as DRY as possible.
angular-automatic-lock-bot commented on Sep 4, 2019
Activity
[-]Create Universal localStorage module[/-][+]Create Universal Storage module[/+]zcoon commentedon Sep 13, 2016
@gdi2290 as this has been taken off of the Beta.0 milestone, do you have a vision for when angular universal will offer localStorage support? Thank you in advance
PatrickJS commentedon Sep 13, 2016
I'm introducing a Universal Cache service that will be used in localStorage after the initial rc6 release
cyrilletuzi commentedon Sep 16, 2016
@gdi2290 For now localStorage is not accepted in my Universal app (everything else is working) and crashes the server, is there something special to import or is it not ready yet ?
PatrickJS commentedon Sep 16, 2016
@cyrilletuzi to transfer state from the server to the client you can use a lifecycle hook in Node and the helper flags
isBrowserandisNodemain.browser.tsmain.node.tsor if you're using the same entry file then it's
PatrickJS commentedon Sep 16, 2016
after I create universal lifecycle hooks for the client then this will be more seamless
joshmvandercom commentedon Oct 3, 2016
@gdi2290 where does UNIVERSAL_CACHE come from? I am running
^2.0.116 remaining items
PatrickJS commentedon Dec 5, 2016
to transfer state from client to server you can simply make an http call
MarkPieszak commentedon Dec 9, 2016
It sounds like you need some initial logic the moment before the app gets serialized, or during, so that it can decide what route to instead render, or components to show,etc ?
What are you trying now?
MarkPieszak commentedon Dec 13, 2016
@WWelling Which file were you trying to do it, let me take a look so I can see what you need.
MarkPieszak commentedon Dec 13, 2016
Is everything working or are you worried about security with this? No worries! Sorry if I'm slow to respond, I've been trying to tackle of a few things at once, it's hard to find time for everything :)
PatrickJS commentedon Jan 8, 2017
won't be supported officially
angular/angular#13822
vforv commentedon Apr 11, 2017
This solution not working for me @gdi2290 @CL0SeY could you help:
http://stackoverflow.com/questions/43350949/how-to-store-token-on-server-side-angular-universal
fulls1z3 commentedon Apr 14, 2017
I made it :)
Have a look at ng-seed/universal for its usage.
Quoted from fulls1z3/universal#5
angular-automatic-lock-bot commentedon Sep 4, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.