2014-10-01 22 views
1

我使用http://vitalets.github.io/angular-xeditable/,看着他們的jsfiddle爲表:http://jsfiddle.net/NfPcH/93/如何更改angular-xeditable的持久性模型?

$scope.saveUser = function(data, id) { 
    //$scope.user not updated yet 
    angular.extend(data, {id: id}); 
    return $http.post('/saveUser', data); 
}; 

我想改變的事實,當地的模型僅持續/後更新保存到遠程服務成功。

1)我該怎麼做?

2)另外,還可以將onbeforesave應用於下拉菜單/ select?

回答

1

我認爲您可以在請求返回承諾後進行更新。

$scope.saveUser = function(data,id){ 
    angular.extend(data, {id: id}); 
    $http.post('/saveUser', data) 
     .then(
      //callback function for success save to server 
      function(response){ 
      //do any of your update here 
      $scope.item = data.item; 
      }, 
      //else handle your error here 
      function(error){ 
      console.log(error) 
      } 
     ); 
+0

原來是'onaftersave',所以我用 – pulkitsinghal 2014-10-02 17:40:43