I am new to Angular JS, have experience on building spring web applications.
My requirement is to store the some session preferences (Not part of the user Model/entity) into session. I need to use them through out the application.
I couldn't find the right way to do it. I found some options, need suggestion on which one to use it.
ngStorage - can access Local/session storage and store attributes in it.
LocalStorageService - another githubproject, i can use it to store in session storage/ local storage.
Based on the articles i found, localstorage keeps the data even after logout, so have to make sure i clean all of them after logout.
What is the common practice to store session attributes?
I am planning to use ngStorage directive and use sessionstorage and store it by encoding with Base64. Is it a good way to do it?
I am using Java 1.7 and Angular JS for building an application. I have used JHipster to generate the application.
Any Help Appriciated!!!!
welcome! Well, depends the situation, localStorage is an excellent option to store attributes, but yes, it has some limitations and you have to remember to delete this. Another options is to use Cookies of angular project to store attributes on Client Side. I used in some projects and works perfectly for my use case. But if you are using Java, the best way is protect this session attributes using Java HttpServletSessions. I Hope it helps.
i had the same issue and i resolved by find the answer of this question: https://stackoverflow.com/a/922058/5995665
I hope it helps.
Related
I wonder what is the best practice for storing lists from different API's and display them without the need to make redundant API requests.
Suppose user logged in - i want to store all the pages static lists for dropdown menus in a way that they will be available to all the controllers - by doing the API requests once.
The options that i came across are the following:
creating a factory and store the data in $rootScope.
Use sessionStorage.
What is the best way?
Consider storing data in rootscope a very bad practice.
I'd suggest using this package
https://github.com/jmdobry/angular-cache
You have nicely explained inside documentation why would you use this package instead of angulars built in $cacheFactory service.
I need to store userdata, should be available to entire application, should be accessible to required controllers, after searching I found a few options to store.
using a service to controllers
$sessionStorage
$localStorage
of all the above could u please tell me which is the best practice? Or is there any other solution other than the above 3.
Using a simple google search might have told you a lot about the best thing? there is no single best thing it's all depends upon your use case.
Services are the best way to interchange data between controllers.
if you don't want to persist the data(if data don't want to be there if the page is reloaded) you can use a service, If you want to persist the data you can use localstorage.
I want to integrate i18n within a ReactJS application that renders on client-side only.
I can handle the internationalization itself with one of the several i18n libraries available, however I was wondering which would be the best way/available options to store whatever language the user has chosen cross-request (like refreshing the page).
Is this something I can handle on the client-side only or do I have to do it server-side and then pass it to the client?
Thank you very much in advance.
You have limited options with storing a users preference using client side technology. Essentially, you are limited to storing these preferences in a cookie.
Any other sort of persisted data should be handled by the server and most likely saved to a database somewhere.
I´d like to know if exists a better way to render a view like this:
For the first load I need bring data from Controller like usual but after apply a filter in same page I need to start use AngularJS and never more uses Razor.
Is there a way to do that ?
Thanks for all.
Yes. you can do that.
Basically, you'd need to add the line below in your view. After you do that, the json is going to be available to the DOM / javascript and angular can take it from there. Hope this help
var json = '#Html.Raw(Model.MyJsonStringForMyCoolAngularJsApp)';
There are multiple ways to implement ASP.Net MVC with AngularJs.
I personally like Mini SPA (Silos). You can watch Miguel A Castro's video here.
You can also download the source at his website.
What it does is when a request comes in, it goes to ASP.Net MVC Route first. Then, Angular Route takes over the rest. It is a very slick design.
FYI: I also use Angular.Net Helpers to generate strongly typed views.
You could use WebAPI project in visual studio to exchange data between frontend and backend. It would go stateless, so to secure the data, you could use a mechanism like JWT.
The frontend would exchange JSONS from/to the backend using REST apis.
Yes. You can make angular views and exchange data using $http.get(/controller/method/). You can also configure routing using ngRoute.
In my app I want to keep track of what the user created, so he doesn't have to do it everytime he closes the app
I have no idea how to do so, except that it might be with XML or JSON.
I have no access to a server, it need to be on the device's memory.
Could someone guide me on what i Need to undersand and what i need to use?
Check Sencha localStorage proxy class http://docs.sencha.com/touch/2.1.1/#!/api/Ext.data.proxy.LocalStorage
It's wrapper around HTML5 local storage capabilities.