How to serialize the ViewModel ($scope) in AngularJS? I'm planning to store the serialized value to a ASP.NET server-side div to persists across postbacks.
相关问题
- Json.NET deserializing contents of a JObject?
- angularJS: ui-router equivalent to $location.searc
- Separate AngularJS Controllers Into Separate Files
- JavaScript variable scope question: to var, or not
- Angular ngAnimate not working first time on page l
相关文章
- Passing variable through URL with angular js
- serializing a list of objects into a file in java
- Watch entire object (deep watch) with AngularJS
- Angular ng-if change span text
- Convert C# Object to Json Object
- Can ng-show directive be used with a delay
- AngularJS $routeParams vs $stateParams
- When sending XML to JMS should I use TextMessage o
I am not sure about how your ASP.Net application is structured, but here are some of my inputs.
If you plan to do postbacks with ASP.Net I would suggest you to rethink you client side framework. AngularJS and many such similar frameworks are not meant for working with postback model. Typically what happens when you use frameworks like AngularJS
From this point onwards there is no post back, most of the functionality is achieved using AJAX requests, which does not cause a browser refresh. If a navigate is performed from one page to another the process described above is repeated again.
As you can see postbacks are not natural to this setup, and any effort to bolt these two model together would produce less than optimum results.
$scope
is an object created by AngularJS to interact with the markup. It can contain methods that can be referenced from html. You can create a simple JavaScript object for storing and transferring data and keep it in your scope.Not sure if you should serialize the whole
$scope
(actually, you shouldn't - it's a complex object. You should only care about persisting your own data).Use:
obviously, there's a method-companion
fromJson
: http://docs-angularjs-org-dev.appspot.com/api/angular.fromJson