0

Hello everyone and thanks for the help and for reading my Post. I have a Service:

var itemsMarker = {};
    itemsMarker.items = [];

so every time I should update the items of itemsMarkers: //here I should clean the itemsMarker.items before and

angular.copy(source, itemsMarker.items);

with that Line of code every time the reference of the variable is not lost, so my directive ng-repeat=itemsMarker.items updates every time the array changes.

But now I do not want to use angular.copy because it is slow.

So I tried to replace it these options:

1.- First Option:
itemsMarker.items.length = 0; itemsMarker.items = _.clone(newArraySameStruct); Reference is gone. the ng-repeat does not update after the change.

2.- Second option I tried: itemsMarker.items.length = 0; itemsMarker.items.push(newArraySameStruct);

but it adds the array newArraySameStruct into itemMarker.items[0][newArraySameStruct]

How can I implement here? Regards.

Angela Pat.
  • 37
  • 2
  • 9

1 Answers1

0

Only for copying we shouldn't include _. underscore library. Not a better solution. You can use angular.extend or other angular methods. Here you can find more information. Should I Use Angular.copy() or _.clone()?

Community
  • 1
  • 1
Mr_Perfect
  • 8,254
  • 11
  • 35
  • 62
  • seems angular.extend is fast. by now is okay. Should you recommend to build my own copy of objects for a future? Because angular.extend is faster than angular.copy but is slow as well. – Angela Pat. Dec 21 '16 at 19:51