If you use jquery, it looks like you are doing this, you can do this:
First create an empty template for your object:
var emptyTemplate = { current: { key1: undefined, key2: [], key3: undefined } }
and then run:
$scope.display = $.extend(true, {}, emptyTemplate);
If you want to automate it, define data binding:
var defaults = { String: undefined, Array: [], bool: false }
Then a loop in your object, like other sentences:
function resetObj (obj) { _(obj).forEach( function(value, key, objRef) { if (_.isObject(value)) { resetObj(objRef[key]); } else { var myvarType = typeOf value; objRef[key] = defaults[myvarType]; } } ); }
I copied this nesting function from another answer by simply adding two cents.
AndreaBogazzi
source share