Javascript 如何使用angular获取数据并使用node.js发送数据?

Javascript 如何使用angular获取数据并使用node.js发送数据?,javascript,angularjs,node.js,Javascript,Angularjs,Node.js,我正在更改node.js应用程序,我使用的是EJS模板引擎,现在我想使用angular 为此,我已经安装了angular,并且运行良好,但现在我想获取数据,为此我使用$http服务: (function($) { app.controller('EventCtrl', ['$scope', '$http', function($scope, $http){ $scope.data; $http.get('/data'). success(function(dat

我正在更改node.js应用程序,我使用的是EJS模板引擎,现在我想使用angular

为此,我已经安装了angular,并且运行良好,但现在我想获取数据,为此我使用$http服务:

(function($) {
  app.controller('EventCtrl', ['$scope', '$http', function($scope, $http){
    $scope.data;

    $http.get('/data').
      success(function(data, status, headers, config) {
        $scope.data = data;

      }).
      error(function(data, status, headers, config) {
        $scope.data = data;

      });

  }]);

}(jQuery));
我在后端发送数据:

  restAPI.GET(options).then(function (result) {
    res.render('data/index.html', {
      event: result,
    });
  }).then(undefined, function (error) {
    console.log(error);
  });
但是它从我使用控制器的同一个页面返回HTML。我做错了什么???

试试这个

$scope.data = data;
config变量应该返回以下内容:

config–{Object}–用于生成 请求


此外,您还可以查看以了解success函数上的所有变量的含义。

我认为您需要为render提供回调函数。例如:

res.render('data/index', {event: result}, function(error, theHtml) {
    console.log(error);
    res.send(theHtml);
})

抱歉,Mário,我复制错了,我使用的是数据,返回的是HTML,而不是真实的数据:B.Oops,我让HTML被记录而不是实际发送!