6

I am baffled by this one. In the angular api and on github there is a merge function which does a deep merge on two objects, unlike extend() which does a shallow copy.

I use google's cdn for angular, and call angular.extend('param') works, but calling angular.merge('param') gives undefined function. Comparing the angular.js from google and the one from angular them selves, merge does exist on the angular one, but not in google.

Any ideas, or someone else with this problem. Could I let google know somehow?

Gerardlamo
  • 1,505
  • 15
  • 21

1 Answers1

11

Feel like a fool, it is only available in the beta version 1.4 Hope this still is able to help someone who is wondering as well. :)

Also copied it from the latest version:

//Leave out the {} to directly change src
function merge(src, newObj) {
   return angular.extend({},src, newObj);
}
Gerardlamo
  • 1,505
  • 15
  • 21
  • 1
    Indeed. Your answer helped a lot. However I wrote a custom function by copying the code for merge functionality, you can use it in the older versions of angularjs - http://stackoverflow.com/a/29003438/548308. By the you can accept your own answer :) – Mathankumar Mar 12 '15 at 06:48
  • Just to note though, this is not a polyfill/replacement for `angular.merge`. – Jim Buck Jun 26 '15 at 14:44
  • 2
    This is not correct. Merge and extend are different. `angular.extend` does not support recursive merge (deep copy) - this is why you have to use `angular.merge` if you want to make a deep copy of your object. – julien bouteloup Oct 08 '15 at 09:38
  • at last i found my question/answer... by the same persion ... ;-) – RJV Oct 17 '16 at 10:09