M
M
Maxim Ivanov2016-12-12 14:38:30
JavaScript
Maxim Ivanov, 2016-12-12 14:38:30

How to replace objects not by reference, but by value?

All in all, changing the parent didn't do me any good, Angular didn't react at all. However, when I simply replaced the properties of the original parent object and called
angular.element($( 'body' )).scope().$apply()
Then Angular redrawn the DOM for me
Please tell me, I have not come across this before, how to correctly replace all the properties of an object with the properties of another object? Is there any normal folk function or method in the standard?
For example:
I have an original object that Angular listens to:

let service = {

    start: false, // запущена ли отрисовка
    ye: 10, // условные единицы
    kq: 1,
    kF: 1,

    base: {
      A: 100, // A
      L: 10, // L
      q: false
    },

    structure: {
      item: [], // KernelList
      F: [],
      leftSealing: false, // заделка слева
      rightSealing: false // заделка
    }
  };

However, I need to be able to easily change the properties of this object to my own and call apply
. For example, with such an object
{
  "start": true,
  "ye": 10,
  "kq": 1,
  "kF": 1,
  "base": {
    "A": 100,
    "L": 10,
    "q": false
  },
  "structure": {
    "item": [
      {
        "A": 100,
        "L": 10,
        "q": false
      },
      {
        "A": 100,
        "L": 10,
        "q": 1
      },
      {
        "A": 100,
        "L": 10,
        "q": false
      },
      {
        "A": 100,
        "L": 10,
        "q": false
      }
    ],
    "F": [
      null,
      null,
      null,
      -1
    ],
    "leftSealing": false,
    "rightSealing": false
  }
}

simple service = newService does not work, Angular just keeps a reference to another object (we lose the link as a result)
I need the service properties to be replaced with newService properties

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Korotaev, 2016-12-12
@splincodewd

have you tried angular.extend(service, newService)?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question