0

I'm trying to display only the updated values in controller but I'm getting complete data. How can I get only updated values?

Input field:

 <div class="" ng-repeat="fields in containerDetails.containerFields">
    <input type="{{features.input}}"  minlength="{{features.rules[0].minlength}}" maxlength="{{features.rules[0].maxlength}}" required name="{{name}}" ng-model="features.name" >
    </div>
<button ng-click="save()">Save</button>

Clicking save should only pass updated values to controller.

 .controller('DemoCtrl', function($scope, $http) {

            $http.get('json/test.json').
            success(function(data, status, headers, config) {
                $scope.containerDetails=data;

                console.log(data);
                $scope.mode=data.containerProperties.mode;
                $scope.user=data.containerProperties.role;
                console.log($scope.user);
                }).
            error(function(data, status, headers, config) {
                console.log("error");
            });


    $scope.save = function() {

    $scope.msg = 'Data sent: '+ JSON.stringify($scope.containerDetails);

        console.log($scope.msg);
  };

I have JSON like:

"containerFields": [

      {
        "label": "First Name",
        "name": "first_name",
        "placeholder": "Enter Your first name",
        "primary": "no",
        "required": "yes",
        "type": "text",
        "input":"text",
        "enum": "false",
        "access":"user",
          "minlength":"10",
            "maxlength":"150",
        "rules": [{
            "message":"Enter First Name",
            "minlength":"10",
            "maxlength":"150",
            "elementValidate":"aplha"
        }]
      },
      {
        "label": "Email",
        "name": "email",
        "placeholder": "Enter Your email",
        "primary": "no",
        "required": "yes",
        "type": "text",
        "input": "email",
        "access":"user",
        "rules": [{
            "message":"Enter valid email",

            "elementValidate":"email"
        }]
      }
]
08Dc91wk
  • 4,254
  • 8
  • 34
  • 67
stackoverflow
  • 63
  • 2
  • 12
  • Check the $pristine property on each field. See http://stackoverflow.com/questions/18641618/how-can-i-denote-which-input-fields-have-changed-in-angularjs – Daniel Beck Jul 07 '15 at 13:34

1 Answers1

0

Write the values in a seperate data structure. The safe function can access all the values via $scope.data.

<input type="{{features.input}}"  minlength="{{features.rules[0].minlength}}" maxlength="{{features.rules[0].maxlength}}" required name="{{name}}" ng-model="data[features.name]" >
Michael
  • 3,085
  • 1
  • 17
  • 15