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.
One thing you will have to do to achieve this in normal angular 2 App is to pass your global service to bootstrap.
I don't think you can do that in Angular 2 universal app unless I am missing something.
I want to store user data and use it across application. Just like Session data in asp.net. And plus this needs to done without making parent-child components
How can I store global variables in Angular 2 Universal App?
You could store it in a Root level Service like normal, and have all your http calls default to passing the Authorization Token to headers. Did you get some type of error when you tried that? @FahadMullaji
I fixed this problem by using angular2-cookies package.
So it was more of a work around than fixing this problem. I was trying store user information so I guess cookies was anyway a better approach.
If you want to store info on a request basis, use service at root module. If you want to store something across multiple requests for a particular user, store ID in cookie for auth and then have the data in redis or somewhere similar on the server side (or just everything in the cookie if it is a small amount of data).
Ok. so I tried my workaround and it worked and it solved my problem but now there is another problem.
Whenever I use cookies to pull data then system throws exception saying "Document is not defined". And then system does not do server side rendering. Which is a huge deal breaker.
So now I need a cookies module for universal which works with serverside rendering.
Activity
MarkPieszak commentedon Sep 25, 2016
You could store it in a Root level Service like normal, and have all your http calls default to passing the Authorization Token to headers. Did you get some type of error when you tried that?
@FahadMullaji
FahadMullaji commentedon Oct 3, 2016
I fixed this problem by using angular2-cookies package.
So it was more of a work around than fixing this problem. I was trying store user information so I guess cookies was anyway a better approach.
jeffwhelpley commentedon Oct 3, 2016
If you want to store info on a request basis, use service at root module. If you want to store something across multiple requests for a particular user, store ID in cookie for auth and then have the data in redis or somewhere similar on the server side (or just everything in the cookie if it is a small amount of data).
FahadMullaji commentedon Oct 12, 2016
Ok. so I tried my workaround and it worked and it solved my problem but now there is another problem.
Whenever I use cookies to pull data then system throws exception saying "Document is not defined". And then system does not do server side rendering. Which is a huge deal breaker.
So now I need a cookies module for universal which works with serverside rendering.
scott-wyatt commentedon Oct 12, 2016
@FahadMullaji there are a lot of open issues for cookies #404 #268 to name a few.
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.