1

I am using ng-repeat, which is getting values from my db and putting it. Now i insert these values into input text which i update. Now i have a save button, which saves the updated values. I am not getting the updated values when i press the save button. Please guide me through this.

<div ng-controller="education" ng-init="getEducationDetails();">
    <div class="col-md-12">
                    <div class="row" ng-repeat="values in education"
                        style="margin-left: 20px; margin-right: 20px; margin-top: 10px;">
                        <div class="col-md-6">
                            <h4>
                                <small>Degree</small>
                            </h4>
                            <input type="text" id="educationDegree" name="educationDegree"
                                value="{{values.education_degree}}" style="width: 90%;" />
                        </div>
                        <div class="col-md-6">
                            <h4>
                                <small>Year</small>
                            </h4>
                            <input type="text" id="educationYear" name="educationYear"
                                value="{{values.education_year}}" style="width: 100%;" />
                        </div>
                        <div class="col-md-12" style="margin-top: 10px;">
                            <h4>
                                <small>University</small>
                            </h4>
                            <input type="text" id="educationUniversity"
                                name="educationUniversity"
                                value="{{values.education_university}}" style="width: 100%;" />
                        </div>
                    </div>
                </div>
                <div class="col-md-12" style="margin: 20px;">
                    <button ng-click="educationSave();" class="btn btn-default">Save</button>
                </div>
</div>

on educationSave() i save the values. But when i get the education array in the educationSave() method, i get the old array. How can i get the updated array, after i adjust some of the input types

Here is how i get the values:

$scope.getEducationDetails = function()
            {
                $http({
                    method : 'GET',
                    url : '/getEducationDetails'
                }).success(function(data, status, headers, config) {
                        $scope.education = data.resultSet;
                        alert($scope.education);
                }).error(function(data, status, headers, config) {
                });
            };

Here is my controller method:

    $scope.educationSave = function() {
        var educationArray = JSON.stringify($scope.education);
        //I then save this educationArray
    };
1
  • Hi @Stealz What would I suggest you is using NgGrid for that purposes , it has a Edit On Focus Cell Selection property just as you need . [link](angular-ui.github.io/ng-grid ) Commented Mar 1, 2015 at 19:29

1 Answer 1

1

The problem is that you are not using ng-model to bind your actual input value to controller. From documentation:

HTML input element control. When used together with ngModel, it provides data-binding, input state control, and validation.

Try something like this in your markup for each input:

<input type="text" id="educationDegree" name="educationDegree"
                            ng-model="values.education_degree" style="width: 90%;" />

See little Demo

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

1 Comment

Absolutely, it works. I am actually new to Angular, i am learning data binding. Thanks !!

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.