2

Friends,

I am using 'merge' function in AngularJs in order to update a JSON from another customized:

angular.merge( original, customized );

Original:

{
"CUSTOM_MODULE_CONFIG": {
    "CUSTOMER": {
        "quickSearch": [
            { ... }
        ],
        "monitors": [
            { ... }
        ], 
        "menuNavigation": [
            { ... }
        ]
    }
}}

Customized:

{
"CUSTOM_MODULE_CONFIG": {
    "CUSTOMER": {
        "menuNavigation": [
            { ... }
        ]
    }
}}

But finally the Original JSON is updated removing "quicksearch" and "monitors" elements. In other examples (without including arrays) the merge function updates the JSON as expected, without removing any element.

How can I preserve all elements in the JSON?

Thanks!

2
  • 2
    are you sure, your objects looks fine and I'm getting the correct output... Commented Dec 28, 2016 at 17:22
  • What @kukkuz said is right, see console output from jsfiddle.net/ztupqjx9 Commented Dec 28, 2016 at 17:35

2 Answers 2

2

From the Angular merge Doc (https://docs.angularjs.org/api/ng/function/angular.merge)

If you want to preserve original objects, you can do so by passing an empty object as the target: var object = angular.merge({}, object1, object2).

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

Comments

0

Try first parameter {}:

angular.merge({}, original, customized );

Comments

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.