繁体   English   中英

在ng-repeat Angular JS中获取更新的值

[英]Getting updated values in ng-repeat Angular JS

我正在使用ng-repeat,它从我的数据库中获取值并将其放入。 现在,我将这些值插入更新的输入文本中。 现在,我有一个保存按钮,用于保存更新的值。 当我按保存按钮时,我没有得到更新的值。 请指导我。

<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>

关于educationSave()我保存值。 但是,当我在educationSave()方法中获得教育数组时,我得到了旧数组。 调整某些输入类型后,如何获取更新的数组

这是我如何获取值:

$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) {
                });
            };

这是我的控制器方法:

    $scope.educationSave = function() {
        var educationArray = JSON.stringify($scope.education);
        //I then save this educationArray
    };

问题是您没有使用ng-model将您的实际输入值绑定到控制器。 文档

HTML输入元素控件。 与ngModel一起使用时,它提供数据绑定 ,输入状态控制和验证。

对于每个input在您的标记中尝试以下操作:

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

小样

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM