How to get a simple object from $ scope in angularjs?

I put the loaded json object in the angular $ scope, but I found that angular adds some structure-dependent properties to it.

I want to send the changed object back to the server, is there a convenient way to remove the angular properties and get a simple object without the properties of the angular scope, for example $$hashkey?

EDIT:

A possible duplicate question does not give the answer that I need.

The call angular.toJsongives me a simple string "$SCOPE", and the call angular.copycauses an error. I think they are not intended to work with the $ scope object?

+4
source share
1 answer

, angular.toJson $scope, : Angular.js#L979

JSON.stringify() angular.toJson() :

JSON.stringify(obj, function(key, value) {
  if (typeof key === 'string' && (key.charAt(0) === '$' || key === 'this')) {
    // ignore any key start with '$',
    // and also ignore 'this' key to avoid a circular reference issue.
    return undefined;
  }

  return value;
});

, .

0

All Articles