1

I have an angularjs web page page which allows me to edit some fields. I load the data from my DB, edit it in the page then save the revised data back to the DB. the DB api requires me to submit for amendments the existing DB data and the revised data. Unfortunately when I save the existing data it is binding to the change which I don't want to do !

function providerCtrl($scope, $location, $routeParams, $http)
{
    $scope.getProvider = function () {
    $http.get(
    '/admin/api/'+$routeParams.channel+
    '/'+$routeParams.provider).success(function(data){
            inputData = data[0];//i want to save this initially but never have it     change again, unfortunately its binding with this $scope.settings field changes :-(
            $scope.settings = data[0];
        });
    }

    $scope.amendProvider = function (settings) {
    console.log($scope.inputData);
    var data = {'old': inputData, 'new' : $scope.settings}
    console.log(data);
    $http({
        url: '/admin/api/' + $routeParams.channel + '/' + $routeParams.provider,
        method: "PUT",
        data: {'old': inputData, 'new' : $scope.settings}
    })
    .success(function(data){
        });
    }

    $scope.settings = {};
    var inputData = {};
    $scope.getProvider();
}

1 Answer 1

2

when I save the existing data it is binding to the change which I don't want to do !

use angular.copy() utility to clone new instance.

See Documentation HERE

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

1 Comment

easy when you know how :-)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.