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?
-
Why not have controller B load the data? You could also use a service to maintain state between controllers.Ben Foster– Ben Foster2014年03月18日 09:10:49 +00:00Commented Mar 18, 2014 at 9:10
2 Answers 2
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...)
Comments
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.