1

I want to transfer an object from one page to another. It's a search results page when clicking on a result it leads to a page needed. So I need to transfer the object which has data of the required result.

I tried using services and factory but the data gets reset whenever I loaded the next page

Also I would need to store client details for other pages too, So I think sessions are a better choice

2 Answers 2

3

It is not possible without server intervention. If you want to share the data on client itself, you need to use Local or Session Storage, which store the information as key-value pairs.

To set an item in the local storage

window.localStorage.setItem("key", "value");

To get an item from the local storage

window.localStorage.getItem("key"); // returns "value"

Local storage is persisted until the browser/you manually clean it. On the other hand, session storage is cleared as soon as the tab/window is closed.

More details here.

Sign up to request clarification or add additional context in comments.

1 Comment

yes, I need the data storage just for the client side I will go through the link thanks.
0

There are few ways, here is one among them. You can use localStorage if you want to trade minor objects or variables across the application.

You can set the object in a localStorage as below

localStorage.setItem('objectNameAsKey', realObjectReference);

You can also stringify the JSON object if needed.

 localStorage.setItem('objectNameAsKey', JSON.stringify(realObjectReference));

Wherever you need this object, you can get it using the key

localStorage.getItem('objectNameAsKey'); 

When you fetch the stringify'd object, you can do as below,

JSON.parse(localStorage.getItem('objectNameAsKey'));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.