我在我的 app.js 文件中写了下面的代码(这是一个 rest api 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");
}
);
};
}])
第一个警告框和第二个警告框出现了。但是
Questions.delete({id:id}).$promise.then(function(data) {
if (data.response) {
$route.reload();
}
不工作。 Questions.delete({id:id}) 是“真”。但它为什么不进去呢?
这是我的其他删除功能代码。
来自模板 list.html
<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;
}
休息 Controller 类
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);
}
}
}
有人能告诉我这里缺少什么吗?。 谢谢,
最佳答案
有一个小错误。当我将私有(private)删除更改为公共(public)删除时,它终于起作用了。
关于javascript - 删除功能不起作用angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36231878/