javascript - Quick Way to "Un-Angularize" a JS Object -


angular adds expando properties, "hashes," etc., deep object structure when two-way binding in use. that's fine, i'm interested in retrieving json snapshot of object tree things belonged there. angular provide way "vanilla" version of bound object?

(i wouldn't want merely store "original value" before binding kicks in, since want reflect changes made via ui.)

short answer:

there's nice built in function:

angular.tojson(yourobj);

longer explanation:

the difference between angular.tojson , json.stringify runs through filter strips out hashes/ids , turns window, document, , scope strings. if want roll own function this: here relevant snippet angular.js source code:

if(/^\$+/.test(key)) {     val = undefined; } else if (iswindow(value)) {     val = '$window'; } else if (value &&  document === value) {     val = '$document'; } else if (isscope(value)) {     val = '$scope'; } 

note: iswindow , isscope functions not exported, you'd need little more hacking function work same way.

source: http://docs.angularjs.org/api/angular.tojson , https://github.com/angular/angular.js/blob/master/src/angular.js

there's angular.fromjson function json.parse.

update it's worth noting $http service automatically when specify model data $http request.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -