小编Col*_*ter的帖子

put请求如何通过Angular,Express和Mongoose工作?

我和朋友正试图弄清楚教程中产生的代码到底发生了什么.我们担心客户端/服务器的流程是一次调用factory.js的第8行:

factory.js

app.factory('postFactory', ['$http', function($http)
{
    var o = {
        posts: []
    };

  o.upvote = function(post){
    return $http.put('/posts/' + post._id + "/upvote").success(function(data){
      post.upvotes += 1;
    });
  };

    return o;
}]);
Run Code Online (Sandbox Code Playgroud)

MongoosePost.js

var mongoose = require('mongoose');

var PostSchema = new mongoose.Schema({
    title: String,
    url: String,
    upvotes: {type: Number, default: 0},
    comments: [{type: mongoose.Schema.Types.ObjectId, ref: 'Comment' }]
});

PostSchema.methods.upvote = function(cb)
{
    this.upvotes += 1;
    this.save(cb);
}

mongoose.model('Post', PostSchema);
Run Code Online (Sandbox Code Playgroud)

expressRouter.js

var express = require('express');
var router = express.Router();
var mongoose = require('mongoose'); …
Run Code Online (Sandbox Code Playgroud)

javascript mongodb node.js express angularjs

6
推荐指数
1
解决办法
612
查看次数

标签 统计

angularjs ×1

express ×1

javascript ×1

mongodb ×1

node.js ×1