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"
        }]
      }
]
1

1 Answer 1

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]" >
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for reply. Please explain me how can i do in that way. thank you
Have a look at code i provided in my answer. Use ng-model="data[features.name]" instead of ng-model="features.name"

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.