[英]Unable to send nodemailer error response from node.js to angular.js
[英]Send a response to Angular.js in Node.js
我使用Angular with Node,并将从GET请求向客户端控制器发送响应。
当我使用本机节点而不是Express.js时,用于发送响应的代码行似乎不起作用
这是我的角度控制器:
app.controller('testCtrl', function($scope, $http) {
$http.get('/test').then(function(response){
$scope = response.data;
});
});
这基本上路由到以下服务器脚本:
http.createServer(function onRequest(req, res){
if(req.method==='GET'){
var scope = 'this is the test scope';
res.json(scope); // TypeError: res.json is not a function
}
}).listen(port);
除非我使用快速服务器,否则res.json()会抛出错误
var app = express();
app.all('/*', function(req, res) {
if(req.method==='GET'){
var scope = 'this is the test scope';
res.json(scope); // OK!
}
}).listen(port);
我很确定json()函数带有节点。 使用本机节点服务器时,如何将响应发送回角度?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.