如何在angularjs中仅显示更新的表单数据?

时间:2015-07-04 10:36:03

标签: angularjs

我试图仅在控制器中显示更新的值,但我正在获取完整的数据。我怎样才能获得更新的值?

输入字段:

multi

单击“保存”只应将更新的值传递给控制器​​。

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

我有JSON之类的:

 .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);
  };

1 个答案:

答案 0 :(得分:0)

将值写入单独的数据结构中。安全功能可以通过$scope.data访问所有值。

<input type="{{features.input}}"  minlength="{{features.rules[0].minlength}}" maxlength="{{features.rules[0].maxlength}}" required name="{{name}}" ng-model="data[features.name]" >