Angularjs 无法发布/api/
我正在尝试使用AngularJS和NodeJS的mongoose模块获取一个Angularjs 无法发布/api/,angularjs,node.js,mongodb,mean-stack,Angularjs,Node.js,Mongodb,Mean Stack,我正在尝试使用AngularJS和NodeJS的mongoose模块获取一个对象文件发送到服务器。我确实得到了对象,但由于无法发布/api/appointment/new错误,它没有被发送到服务器 这是我的HTML文件: <div class="row"> <div class="col-sm6 col-sm-offset-3"> <div class="row"> <strong>D
对象
文件发送到服务器。我确实得到了对象
,但由于无法发布/api/appointment/new
错误,它没有被发送到服务器
这是我的HTML
文件:
<div class="row">
<div class="col-sm6 col-sm-offset-3">
<div class="row">
<strong>Date:</strong>
<label>
<input type="text" type="date" ng-model="new.date" class="form-control">
</label>
<strong>Name Surname:</strong>
<label>
<input type="text" ng-model="new.nameSurname" class="form-control">
</label>
</div>
<div class="row">
<strong>Case:</strong>
<label>
<input type="text" ng-model="new.description" class="form-control">
</label>
<strong>Contact number:</strong>
<label>
<input type="tel" ng-model="new.contactNumber" class="form-control">
</label>
<button ng-click='createAppointment()'>Create appointment!</button>
</div>
</div>
</div>
服务器控制器:
var mongoose;
mongoose = require('mongoose');
var appointment;
appointment = require('../datasets/appointment.js');
module.exports.create = function(req, response) {
console.log(req.body)
};
(function() {
//noinspection JSUnresolvedFunction
angular.module('dentalAdviser')
.controller('appointmentController', ['$scope', '$state', '$http', function ($scope, $state, $http) {
$scope.createAppointment = (function() {
console.log($scope.new);
$http.post('api/appointment/new', $scope.new).success(function (response) {
}).error(function (error) {
console.log(error);
})
});
}])
}());
应用程序控制器:
var mongoose;
mongoose = require('mongoose');
var appointment;
appointment = require('../datasets/appointment.js');
module.exports.create = function(req, response) {
console.log(req.body)
};
(function() {
//noinspection JSUnresolvedFunction
angular.module('dentalAdviser')
.controller('appointmentController', ['$scope', '$state', '$http', function ($scope, $state, $http) {
$scope.createAppointment = (function() {
console.log($scope.new);
$http.post('api/appointment/new', $scope.new).success(function (response) {
}).error(function (error) {
console.log(error);
})
});
}])
}());
和对象的数据集:
var mongoose = require('mongoose');
module.export = mongoose.model('appointment', {
nameSurname: String,
date: String,
description: String,
contactNumber: String
});
这:
应该是:
app.post('/api/appointment/new', newAppointment.create);
我不敢相信我错过了这个。。。非常感谢。