将Express NodeJS的值传递给AngularJS控制器variables

我想从快速NodeJS服务器传递一些值到AngularJS控制器variables。 这里是代码片段….

服务器

app.post('/run-engine', function(req, res){ console.log(req) res.writeHead(200, {'Content-Type': 'text/html'}); fs.readFile('index.html', 'utf-8', function(err, content) { if (err) { res.end('error occurred'); return; } var reconData = 'some temp'; //here I assign temp variable with needed value var renderedHtml = ejs.render(content, {data: reconData}) res.end(renderedHtml); }); }); 

HTML代码片段

 <section class="mdl-layout__tab-panel tab2" id="scroll-tab-2"> <div class="page-content"> <h1>This is Tab2</h1> Data: <%= data %> <form method='post' action='run-engine' enctype="multipart/form-data"> <input type='file' name='fileUploaded'></input> <input type='submit'></input> </form> </div> </section> 

在html页面中,我可以看到“reconData”(从服务器post方法的内容中的'data'呈现的值)。

我想要在angularjs控制器中将相同的'reconData'作为范围variables(engineData)进行分配,但是我无法这么做… Angular js controller code snippet

 var myApp1 = angular.module('msnapp',[]); myApp1.controller("MsnController", function($scope, $http) { $scope.engineData = ?? //this needs to be equal to reconData from server side }); 

我如何让engineData从服务器分配为'reconData'?

尝试这个

 var myApp1 = angular.module('msnapp',[]); myApp1.controller("MsnController", function($scope, $http) { $http({ method: 'POST', url: '/run-engine' }).then(function (response){ $scope.engineData = response.data; }, function (error) {}); });