编辑ng-repeat的值

时间:2015-06-17 08:30:19

标签: html angularjs angularjs-ng-repeat

我对angularjs很新。我正在尝试编辑$ scope.works中的数据。我也尝试过xeditable,但是不能用它做很多事情。我知道这很简单。但你的答案真的很有帮助。谢谢。

这是我的代码 -

我的angular.js代码 -

  $scope.works=[{id:'01', position:'web designer' ,place:'Artle'        ,month:'April',year:'2014',month1:'April',year1:'2015',city:'delhi'},
        {id:'02', position:'web designer' ,place:'Artle' ,month:'April',year:'2014',month1:'April',year1:'2015',city:'delhi'}];    



  $scope.editEnabled= false;

  $scope.editData=function(work){
    work.editEnabled = true;
  };

  $scope.saveData=function(data, id){

       angular.extend(data, {id: id});
return $http.post('/saveData', data);
  };


    $scope.close=function(work){
     work.editEnabled = false;
    }
   $scope.editEnabled = false;
  $scope.disableEdit= function(){
    $scope.editEnabled = false;
  };
}); 

为了编辑和保存更改,我的html是 -

      <span ng-hide="work.editEnabled">
       <button ng-click="editData(work) ">Edit</button>
   </span>
   <span ng-show="work.editEnabled">
       <button ng-click="close(work);saveData($data, work.id); ">Save</button>


</script>

点击编辑后,我在输入中显示了值。问题是,点击保存输入中的新更改将不会保存,它会显示在$ scope.works

1 个答案:

答案 0 :(得分:2)

您的保存数据无效,其绑定错误地将其更改为:

<button ng-click="saveData(work, work.id); ">Save</button>

您需要传递work数据而不是$datang-clik中删除两个函数,只保存数据,并在saveData函数中调用close

 $scope.saveData=function(data, id){
      $scope.close(data);
       angular.extend(data, {id: id});
       return $http.post('/saveData', data);
  };