以下是我的server.js文件中的内容,这似乎工作正常,直到它要求我公共的GET / POST请求> javascripts> app.js文件(请参阅下面的app.js语法
Object1 = function() {
this._list = [];
};
Object1.prototype.method1 = function(param) {
if (param == "foo") { this.method2("foo"); }
};
Object1.prototype.method2 = function(param) {
for (var i = 0; i < this._list.length; i++) {
if (this._list[i]._name == param) {
console.log(this._list[i]._name); // outputs "foo"
return this._list[i]._name // **TypeError: value is undefined**
}
}
};
Object2 = function(name) {
this._name = name || "foo";
}
var object = new Object1();
var foo = new Object2("foo");
object._list.push(foo);
object.method1("foo");
这是我的公开&gt; javascripts&gt; app.js文件
var express = require('express');
var app = express();
var router = express.Router();
var pg = require('pg');
var path = require('path');
// set the port of our application
// process.env.PORT lets the port be set by Heroku
var port = process.env.PORT || 3000;
// set the view engine to jade
app.set('view engine', 'jade');
// make express look in the public directory for assets (css/js/img)
app.use(express.static(path.join(__dirname, './client', 'public')));
app.get('/', function(req, res, next) {
res.sendFile(path.join(__dirname, 'views', 'index.html'));
});
// set the home page route
// app.get('/', function(req, res) {
// // jade render automatically looks in the views folder
// res.render('index');
// });
app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});
提前感谢您的帮助!
答案 0 :(得分:0)
您必须在NodeJs应用程序中定义API的端点。 在您的代码中,只有一个获取路径用于&#39; /&#39;,而不是AngularJs控制器中的必需路由......
尝试将这些添加到您的server.js文件中:
app.get('/api/v1/todos', function(req, res, next) { ... }
app.post('/api/v1/todos', function(req, res, next) { ... }
app.delete('/api/v1/todos/:param', function(req, res, next) { ... }