1

I want to pass a lot of data (json) when routing to a new controller in angular.
In controller A I call $location.path('/B'); which in turn will route to controller B.
I know I can pass parameter in the url itself, but I have a lot of data.
Can angular do something similar to 'POST' method and pass data in this way?

asked Mar 18, 2014 at 9:03
1
  • Why not have controller B load the data? You could also use a service to maintain state between controllers. Commented Mar 18, 2014 at 9:10

2 Answers 2

3

No need to bother with POST like behavior with angular.

You have several ways to do this :

  • use a service that will preserve data across page loads
  • pass real GET argument (when the page is specifically linked to this argument, for example an object ID used to display this object details)
  • store data in local storage / session storage
  • use controller 'resolve' functionnality to fetch new data before displaying page (not what you want to do though...)
answered Mar 18, 2014 at 9:14
Sign up to request clarification or add additional context in comments.

Comments

1

Remember you're not actually changing the page, so you don't need to 'POST' data anywhere or do anything similar.

Instead you should create a service that makes that data available through dependency injection, then specify the dependency when you instantiate the controller that handles the new route.

answered Mar 18, 2014 at 9:12

2 Comments

Service feels to me like preserving a state. I would like something like passing parameteres to method. For example, If I refresh the page I am relying on the service state which might be different.
Put some context around your question and I will try to help to give a better answer.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.