1
id我進入控制器,但其nt進入服務器,當我點擊刪除我在控制檯中得到id。其示值誤差 「可能未處理拒絕」,並錯誤404
這是我的服務器: -
var express=require('express');
var mongojs=require('mongojs');
var bodyParser=require('body-parser');
var app=express();
var db=mongojs('contactlist',['contactlist']);
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json());
app.get('/Contactlist',function (req,res) {
console.log("ireceived a get request")
db.contactlist.find(function (err,docs) {
console.log(docs);
res.json(docs);
})
})
app.post('/Contactlist',function (req,res) {
db.contactlist.insert(req.body,function (err,doc) {
res.json(doc);
console.log(doc);
})
})
app.delete('/contactlist/:id',function (req,res) {
var id= req.params.id;
console.log(id);
})
app.listen(3000);
console.log('Server running on port 3000');
這是我這裏控制器
var ContactListApp = angular.module('ContactListApp',[]);
ContactListApp.controller('AppCtrl',[ '$scope','$http',function($scope,$http) {
console.log("controller");
var refresh=function() {
$http.get('/Contactlist').then(success,error)
function success(response) {
console.log(response,"I got the data i requested")
$scope.Contactlist=response.data;
}
function error(response){
alert("Please check your code");
}
};
refresh();
$scope.addContact=function() {
console.log($scope.contact);
$http.post('/Contactlist',$scope.contact).then(success,error)
function success(response) {
console.log(response);
$scope.Contactlist=response.data;
refresh();
};
function error() {
alert('error occured');
}
$scope.contact =null;
}
$scope.remove=function (id) {
console.log(id);
$http.delete('/contactlist/',id);
refresh();
}
}]);
@Dhiraj夏爾馬請更新是否有所幫助 –