router.post返回错误“undefined不是函数”。使用mongo和express.js

在这里输入图像描述 我试图buld一个应用程序使用来自LINK的文件。我发现张贴是代码breaks.Hasexpressionjs更改或是语法错误?

router.post破一旦到达Maid.registerMaid(新的女仆({…我可以使它使用.save(),但任何人都可以解释为什么这个callback是beaking?

把代码放在下面..对不起,我是一个初学者在平均水平

API.js

var express = require('express'), router = express.Router(), passport = require('passport'); User = require('../models/user.js'); Maid = require('../models/maid.js'); router.post('/AddMaid', function(req, res) { console.log(req.body, req.body.FirstName,req.body.LastName); Maid.registerMaid(new Maid({ FirstName: req.body.FirstName }), ({LastName: req.body.LastName}), function(err, account) { if (err) { return res.status(500).json({err : err}) } return res.status(200).json({status: 'Registration successful!'}); }); 

});

Services.js

 angular.module('myApp').factory('AuthService',['$q', '$timeout', '$http', function ($q, $timeout, $http) { var user = null; return ({ isLoggedIn: isLoggedIn, getUserStatus: getUserStatus, login: login, logout: logout, register: register, registerMaid: registerMaid }); function registerMaid(Fname, Lname) { var deferred = $q.defer(); $http.post('/maid/AddMaid', { FirstName : Fname, LastName : Lname }).success(function(data, status) { if (status === 200 && data.status) { deferred.resolve(); } else { deferred.reject(); } }).error(function(data) { debugger; alert("Error in Services AddMaid"); deferred.reject(); }); return deferred.promise; } }]); 

Controllers.js

 angular.module('myApp').controller('AddMaidController', ['$scope', '$http','$location', 'AuthService', function($scope, $http,$location, AuthService) { console.log(AuthService.getUserStatus()); $scope.register = function () { $scope.error = false; $scope.disabled = true; AuthService.registerMaid($scope.registerForm.FirstName,$scope.registerForm.LastName).then(function () { $scope.disabled = false; $scope.registerForm = {}; }).catch(function () { $scope.error = true; $scope.errorMessage = "Something went wrong!"; }); };}]); 

maid.js

 var mongoose = require('mongoose'), Schema = mongoose.Schema; var Maid = new Schema({ First_Name: String, Last_Name: String }); module.exports = mongoose.model('maids', Maid); 

       

网上收集的解决方案 "router.post返回错误“undefined不是函数”。使用mongo和express.js"