2016-03-26 5 views
3

が動作していない(これは、REST APIのあるプロジェクトangularjs)削除機能は、私は私のapp.jsファイル内のコードの下に書いたangularjs

.controller('HomeCtrl'['$scope','Questions','$route',function($scope,Questions,$route) { 

    var id = $route.id; 

    Questions.get(function(data) {    
     $scope.questions = data.response; 
    }); 

    $scope.remove = function(id) { 

     window.alert("works"); 
     //var id = $scope.question[id]; 
     // document.write(id); 

     Questions.delete({id:id}).$promise.then(function(data) { 
      if(data.response){     
       $route.reload();     
      }     
     } , function(){ 
       alert("2nd"); 
      } 

     ); 
    }; 
}]) 

最初の警告ボックスと第二警告ボックスがapearingされます。しかし

Questions.delete({id:id}).$promise.then(function(data) { 
    if (data.response) {     
     $route.reload();     
} 

は機能しません。 Questions.delete({id:id})は "true"です。なぜそれが内部に入っていないのですか?

ここに私の削除機能のコードがあります。

<a class="trash" ng-click="remove(question.id)"><span class="glyphicon glyphicon-trash"></span></a> 

残りのモデルクラス

private function delete($id) {  

    $this->db->where('id',$id)->delete('questions'); 

    if ($this->db->affected_rows() === 1) { 
     return TRUE; 
    } 

    return NULL;  

} 

残りコントローラクラス

public function index_delete($id) { 

    if (!$id) { 
     $this->response(NULL,400); 
    } 

    $delete = $this->questions_model->delete($id); 

    if(!is_null($delete)) { 

      $this->response(array("response" =>"deleted"),200); 

    } else { 

     $this->response(array("error" => "cud not save"),404); 

    } 

    } 

} 

するlist.htmlテンプレートから

は、いくつかの一つがここに欠けているものを私に伝えることができます?。 ありがとう、

+0

質問は実際にDBから削除されていますか? 'if(data.response.deleted){'をチェックする必要はありません(サーバーから実際に返されたものを見るために約束成功コー​​ルバックに 'console.log(data)'を書きます) –

+0

data.response .deletedは私のために働かなかった –

答えて

0

少し間違いがあります。プライベート削除をパブリック削除に変更したとき、それは最終的に機能しました。

関連する問題