Angular 1.3.14 merge(dst) does not exist
Asked Answered
C

1

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?

Consequently answered 11/3, 2015 at 7:56 Comment(0)
C
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);
}
Consequently answered 11/3, 2015 at 8:7 Comment(4)
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 - https://mcmap.net/q/406671/-deep-merge-objects-with-angularjs. By the you can accept your own answer :)Addington
Just to note though, this is not a polyfill/replacement for angular.merge.Barmecidal
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.Copalite
at last i found my question/answer... by the same persion ... ;-)Senega

© 2022 - 2024 — McMap. All rights reserved.