1

How can I use JQuery $.extend in Angular2 without using Jquery?

I try to use Object.assign but deep merging does not work.

An example here: https://codepen.io/anon/pen/NvGPOv

Object.assign( baseOptions, customOption);
4
  • 2
    I use lodash. You can install the merge function seperately: npmjs.com/package/lodash.merge Commented Jul 28, 2017 at 8:14
  • You can always extract the function... Commented Jul 28, 2017 at 8:14
  • lodash merge works... thanks Commented Jul 28, 2017 at 9:45
  • did you find something? Commented Mar 14, 2019 at 0:48

1 Answer 1

2

Angular 2/4 does not provide any way to perform deep copy. It does not offer any opinion or implementation on deep copy of Javascript objects.

If your object does not contain functions or date objects then the below approach using pure Javascript way can work for you in most cases:

var clonedObject = JSON.parse(JSON.stringify(obj));

Once the object is cloned, you can assign additional properties to it.

Sign up to request clarification or add additional context in comments.

1 Comment

Possibly merge function should be the most generic possible... In my case I have function also in the object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.