Mikhail Moskalev2014-04-17 14:50:07
Mikhail Moskalev, 2014-04-17 14:50:07

Angular, $save() method. How to prevent angular internal methods ($promise, $resolve etc) from being forwarded along with post?

Good afternoon! There is this code:

$scope.invoice = Invoices.get({invoiceId: '1'})
$scope.invoice.test = 'test';

Not only data goes to the server, but also internal methods of Angular ($promise, details[1].$$hashKey, $resolved, etc.).
I correctly understood the work with the data, or is my approach not correct and it is impossible to save it this way? Has anyone encountered a similar problem, and if so, how did you solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Sergey Gavrilov, 2014-04-18

By default, Angular passes the data through the defaults.transformRequest function before sending it.
Check up can somewhere changed this function in $http configs.

// transform outgoing request data
    transformRequest: [function(d) {
      return isObject(d) && !isFile(d) ? toJson(d) : d;

function toJson(obj, pretty) {
  if (typeof obj === 'undefined') return undefined;
  return JSON.stringify(obj, toJsonReplacer, pretty ? '  ' : null);

function toJsonReplacer(key, value) {
  var val = value;

  if (typeof key === 'string' && key.charAt(0) === '$') {
    val = undefined;
  } else if (isWindow(value)) {
    val = '$WINDOW';
  } else if (value &&  document === value) {
    val = '$DOCUMENT';
  } else if (isScope(value)) {
    val = '$SCOPE';

  return val;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question