I am trying to pass some values from express NodeJS server to AngularJS controller variable. Here is the code snippet....
Server
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 code snippet
<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>
In the html page, I could see the value of "reconData" (which is rendered by 'data' in the content from server post method).
I want the same 'reconData' to be assigned as scope variable (engineData) in angularjs controller but I am unable to do so... 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
});
How do I get the engineData to be assigned as 'reconData' from server?