Required Scenario
I have 4 pages Registration form, If we close the window without completing the Registration, then we have to auto drive the page while loading.We are saving the data in local storage but we want send the data object to the Dynamic Routing Page in the application. can we have chance to add the parameters while Routing.
If I am in the wrong direction please suggest me the proper way.
Related
What is preferred way to share data (Object) between controllers with different routes and prevent data lost after reloading?
I need this object to prefill form values in my destination page which depends on choices in my source page.
Solutions I got so far are:
1- to send serialized Objects as query string parameter.
2- or using local storage and give special parameter to url so it knows when to fetch from local storage and when to open empty form.
Solutions which I can't use:
1- Shared service as my data would be lost after reload in this case.
Is there any other way, if not which way is more preferred?
note: there has to be no lost data after reloading page.
IMHO , there could be only 2 ways to handle this:
Using localStorage or sessionStorage
You use session management from server side keep the session consistent.
If it's just about retaining the data after page reload for a route, just go for sessionStorage. But it depends on the use case of your project.
I have an AngularJS app like this one:
http://next.plnkr.co/edit/Wtkv71LIqUR4OhzhgpqL?p=preview&preview
and the $scope data that I have, is from an API,
When the page first loaded I call to this API and I save the data that returned in the session,
Now I can't understand why when I refresh the page I Losing information and all the data,
How can I use the data dynamic that when I refresh the page I don't loos data?
First of all, are you using routing in your app? Here is simple example :
http://next.plnkr.co/edit/Svg4Po13hMq7WxzNwKDc?p=preview&preview
With routing you do not need to refresh your page.
As to the problem itself (don't loss data after refresh):
if you want to keep your data even when you refresh your browser use localStorage. There're lots of handy localStorage angularJS modules to use - ex.
https://github.com/grevory/angular-local-storage
if you don't want to store data on the client side, you could request your API for the data you need to store each time your angular app is getting loaded. This data seems to be static, as you are storing it on client side and reuse then, so you could configure API endpoint to throw this data really fast.
I have graph with data in welcome page like widget(/welcome). when the user clicks the graph the page change to /home/default and the same graph should be displayed along with some extra data which is populated by Ajax call. What I want is to persist the graph data from /welcome into /home/default page. I don't want the data to go controller and back to the /home/default page. Kindly suggest.
In a nutshell, you need to set some state for the user and then when the /home/default page is rendered, you need to check that state and make corresponding changes to the presentation of the page.
This can be done either server-side (in the rendering of the page) or client-side (via Javascript adding things to the page).
If you do this client-side, then the state can be stored in a cookie, in LocalStorage or in a query parameter in the URL when you redirect. Then, you place Javascript code into /home/default that checks that state and adds content to the page dynamically based on the state.
If you do this server-side, then the state can be stored in a cookie or in some server-side data store and then when the /hoome/default page is rendered, your server side page rendering process can check the state for this particular user and modify the rendering of the page to include the desired content.
You have a plethora of options. The best solution depends on how your application is currently implemented -- whether in a framework or not, with sessions or not, etc. The principle whatever method you choose is almost identical: store a value and then retrieve it later.
Single Page Application (SPA)
If you aren't already using a framework, I would urge you to consider migrating to one as tasks like these are made infinitely more elegant in their implementation.
Service / Data Store
If you are building an SPA then you may not have to consider any of the options below... so long as it doesn't matter if the data is lost if the user performs a 'real' navigation that cannot be intercepted by the framework (for example, refreshing the page).
In Angular you can maintain a temporary data store in the form of a service. Simply store the data and then pick it up later from another controller. Similar functionality can be achieved in all other popular SPA frameworks:
Angular
Ember
React
Local Storage
Local Storage is available in IE8 and above and has a really simple API.
Angular: angular-local-storage
React: react-local-storage
Ember: ember-local-storage-adapter
jQuery: jStorage
IndexedDB
If you're into the cutting edge and aren't tied down by browser support, consider using IndexedDB. I don't recommend using this unless you are wanting to persist large amounts of data remotely on the client's machine. (It really does have bad support at the moment.)
Angular: angular-indexed-db
React: ???
Ember: ember-indexeddb-adapter
jQuery: jquery-indexeddb
Cookies
If your application is inflexible then cookies will be the easiest and least time-consuming. However Local Storage may be a contender.
Angular: $cookie service
React: react-cookie
Ember: ???
jQuery: jquery-cookie
I currently have an angular app which contains 2 pages.
When the user finishes with page1, I create a variable with some data he entered on that page and put it in the main controller (a controller above the 2 pages). Then the state changes (he get redirected to page2) and page2 reads the data from the main controller.
Now I want to split the 2 pages into 2 diffirent web sites with diffirent addresses. How can I open page2 from page1 with parameters (GET is not an option, the data is more then what is allowed for url).
NOTE : Both pages are written in angular and page2 is currently not in MVC - its just simple HTML, css and js files. But if someone has a solution involving minimal MVC - its great.
You can do it trough a hidden form. It will submit your data as POST whatever the target url is
There are multiple ways you can do that
Completely client side solution
Using cookies / local storage - i have been using angular storage library to perform exactly what you are trying to do. This solution will not work if you are putting the pages on 2 different domains. As the cookies and localstorage can only be read by the domain they are created by.
Solutions requiring to save the state on server side and then accessing them on the second page.
Its easy to use sessions / temporary sessions to storage data server side.
Using a third party state storage is also possible ex. Firebase.
Solutions not requiring you to save the state at all but require you to handle POST data on the server side
Make a hidden form on page1. With action attribute pointing to the url of the page2. Keep the data inside form using ng-model etc. when you are ready to make the transition POST / Submit the form. Handle the POST data on the second website / url and inject it into the second page
I want to create an application i.e svg-edit that use javascript for client side operations but I want to integrate it with ExpressJS.
Task needed:
1. User Authentication page
2. After authentication depending on the user name the user is directed to the svg-edit page but the background image and the svg is the value from the database.
3. Auto saving and saving on close.
For this I have using ExpressJS and svg-edit 2.6.
My Approach:
1. I will create a page auth.html in /views of Expresss
2. Post the page and in the route handler authenticate it and then redirect to the svg-edit.html the whole folder with all its related .js files are put into /views so it will redirect it.
The porblem is that when server redirects i want to send the image location, username to the svg-edit.html page so that it changes the background w.r.t the value gained.
What is the best way to do such an operation.
Since I am new at ExpressJs so before writing the code. I need suggestion for the structure.