2015-07-21 60 views
3

怎麼能檢查什麼是真正happning客棧刪除功能上的資源,因爲每次我刪除它的時候說的成功,但是在UI犯規更新檢查刪除和更新UI的角度ngResource模塊

我的HTML

 <md-content > 
        <div id="main" class="well"> 

         <table cellpadding="20" class="table table-bordered table-striped"> 
          <tr> 
           <th ng-repeat="(head, value) in models[0]"><span>{{head}}</span></th> 
          </tr> 
          <tr ng-repeat="row in models"> 
           <td ng-repeat="(name, value) in row" ng-scope> 
            <span ng-click="" ng-bind="row[name]"></span> 


           </td> 
           <td > 
            <a target="_self" href="#" ng-click="downlaodId(row)">Downlaod</a> 
           </td> 
           <td > 
            <a target="_self" href="#" ng-click="deleteId(row)" 
             confirmation-needed="Really Delete?">Delete</a> 
           </td> 
          </tr> 
         </table> 

        </div> 

    </md-content> 

我的控制器

$scope.deleteId = function (idPassed) { 

    fileLoadService.delete({ 'id': idPassed.id },function(successResult) { 
     alert('Deleted'); 
    }, function (errorResult) { 
     // do something on error 
     if (errorResult.status === 404) { 
      alert('Ooops'); 
     } 
    }); 

}; 

我的UI看起來是這樣的後單擊刪除 fileLoadservice

app.factory('fileLoadService', ['$resource', 
      function ($resource) { 
       return $resource(
    "http://jsonplaceholder.typicode.com/todos/:id", 
    { id: "@id" }, 
    { 

     "query": { 'method': 'GET', isArray: true } 

    }); 

}]);

enter image description here

+0

您應該更新您的刪除 – user2718281

回答

3

你可以從你的代碼中看到:

$scope.deleteId = function (idPassed) { 

    fileLoadService.delete({ 'id': idPassed.id },function(successResult) { 
     alert('Deleted'); 
    }, function (errorResult) { 

你什麼都不做,以目前的模式,只需發送一個警報Deleted當你點擊刪除按鈕。如果你想讓它做別的事情.....你應該把這個功能放在代碼中。

例如:

$scope.deleteId = function (idPassed) { 

     fileLoadService.delete({ 'id': idPassed.id },function(successResult) { 
      var index = $scope.models.indexOf(idPassed); 
      $scope.models.splice(index, 1); 
      alert('Deleted'); 
     }, function (errorResult) { 
+0

'model'什麼ü意味着什麼呢?這是一個方法(deleteId(id))由UI中的按鈕調用。 fileLoad服務返回資源。我怎麼想她 –

+0

你的模型從不更新。如果您希望更改反映在當前屏幕上,則需要更新模型。請檢查我上面發佈的代碼。 –

+0

謝謝,它在ui上工作,但不知道api是否正在刪除api,因爲當我重新加載頁面時,它剛剛出現。 jsonplaceholder api是否會持續改變一段時間 –