0

I have a page A. On Submit of it, it need to render Page B with the values entered on PAge A. Page A is mapped to a controller A and on click event i am invoking Spring controller for rendering the Page B.

Issue is i am not able to fetch Page A details and show up on Page B. I tried shared service, but as soon as it reaches Page B controller, it becomes undefined.

Help is much appreciated.

2 Answers 2

1

try using $rootscope

set the values to rootscope in the first controller and read it from the second controller.

upgrade your navigations to use route so that you can send some parameters as routeparams also

writing to the local storage is also an approach if your design allows so.

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

8 Comments

writing to the local storage is also an approach if your design allows so.
i tried $rootscope. But the proble is from controller A it invokes Spring Controller and this returns a view Page B and Page B angular controller is invoked. In this case rootscope value is coming as undefined in Page B angular controller.
in your both pages are not in the same angular scope. so try local storage.
or you can take the data with you to server (spring) and serve it over response.
Its served back in response from Spring. But the problem in this case is it is not redirecting to Page B. It displays Page A itself. My Spring method returns ModelAndView object with view name as Page B.
|
1

If you are using routing concept of angular js then in rootscope you can store that data but if you submit the page then angular scope is loss then ultimately you will get the undefined data.

because angular js is used for single page application. optional solution is you can store it in a localstorage of html5 or send the data with the request and and reused it.

i.e when you are calling the request which return page B then with request you can send the data to server then return this data with response of the spring request but then you have to send json response.

3 Comments

But i need to render it to new html page. Currently i am sending the data to server and setting it up in model. But it is not rendering to Page B. I want to get the details of Page A in Page B. I am not using angular router, instead i am using spring controller for routing purpose. From angular controller using windows.location.href to spring controller. Is there any better approach in angular for passing Page A details to Page B. Both pages are using different angular controller.
Then storing it localStorage is one approache you can use, but in that case you need to stringify the page A data and then you need to store it in localstorage and when your page B is load then you need to get this data from localstorage by parsing it to json again. In localstorage you can store the data as map like ---> localstorgae.set("pageAData","data of page"); but ensure it you need to stringify it while stroring and Json.parse it while rertiving it in a page B.
when you will send your request to your string controller you need to store page A data in localstorage and when your page B is render then you need to acces that data from localstorage

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.