我无法使用angular 2发布到我的mongodb服务器
您好,我在发布到mongodb数据库时遇到问题。我似乎无法将任何内容发布到我的server.js。我尝试使用ngmodel将我的表单连接到我的帖子,但它表明找不到我的call_帖子。但是我不确定这是否是唯一的问题。有人能给我指一下正确的方向吗。多谢各位 server.js我无法使用angular 2发布到我的mongodb服务器,mongodb,http,post,angular,Mongodb,Http,Post,Angular,您好,我在发布到mongodb数据库时遇到问题。我似乎无法将任何内容发布到我的server.js。我尝试使用ngmodel将我的表单连接到我的帖子,但它表明找不到我的call_帖子。但是我不确定这是否是唯一的问题。有人能给我指一下正确的方向吗。多谢各位 server.js var express = require('express'), app= express(), engines = require('consolidate'), MongoClient = require('mo
var express = require('express'),
app= express(),
engines = require('consolidate'),
MongoClient = require('mongodb').MongoClient,
assert = require('assert');
bodyParser = require('body-parser');
var app = express();
app.engine('html', engines.nunjucks);
app.set('view engine', 'html');
app.use(express.static(__dirname + '/'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// view engine setup
// catch 404 and forward to error handler
MongoClient.connect('mongodb://localhost:27017/munchies', function(err, db){
assert.equal(null, err);
console.log("Successfully connected to MongoDB.");
app.get('/', function(req, res){
res.render('index.html' );
});
app.get('/name', function(req, res){
db.collection('names').find().toArray(function(err, docs) {
if (!err) {
console.log(docs);
res.json(docs);
}
else{
console.log(err);
}
})
});
app.post('/calls', function(req, res) {
console.log("Post body.value is "+ req.body.value)
req.assert('value', 'An integer >= 0 is required').isInt()
if (req.body.value < 0) {
console.log("invalid integer (less than zero)")
res.status(400).send('Invalid integer')
}
get_counter = parseInt(req.body.value, 10);
console.log("get_counter" + get_counter)
res.status(200)
});
app.use(function(req, res){
res.sendStatus(404);
});
var server = app.listen(3000, function() {
var port=server.address().port;
console.log('express server listening on port %s', port);
});
});
module.exports = app;
尝试更改此选项:
app.component.ts:
public call= this.call_post;
doPost() {
this._demoService.post(this.call);
}
为此:
public call_post;
doPost() {
this._demoService.post(this.call_post);
}
尝试更改此选项:
app.component.ts:
public call= this.call_post;
doPost() {
this._demoService.post(this.call);
}
为此:
public call_post;
doPost() {
this._demoService.post(this.call_post);
}
感谢您的帮助,我做了更改,但我认为当我发布帖子时,demo.service.ts可能仍然存在问题()例外情况是什么?感谢您的帮助,我做了更改,但我认为当我发布帖子时,demo.service.ts可能仍然存在问题()例外情况是什么?