I wrote below code in my app.js file (this is a rest api angularjs project)
.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");
}
);
};
}])
first alert box and second alert box is apearing. but
Questions.delete({id:id}).$promise.then(function(data) {
if (data.response) {
$route.reload();
}
is not working. Questions.delete({id:id}) is "true". but why don't it go inside?.
Here are my other codes for delete function.
from template list.html
<a class="trash" ng-click="remove(question.id)"><span class="glyphicon glyphicon-trash"></span></a>
rest model class
private function delete($id) {
$this->db->where('id',$id)->delete('questions');
if ($this->db->affected_rows() === 1) {
return TRUE;
}
return NULL;
}
rest controller class
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);
}
}
}
can some one tell me what is missing here?. Thanks,
if(data.response.deleted){(If not - writeconsole.log(data)in the promise success callback to see what is actually returned from the server)