简体   繁体   English

显示从nodejs服务器发送的文件数据,就像在angularjs中一样

[英]display file data sent from nodejs server as it is in angularjs

I am using angular fullstack generator for creating a web application. 我正在使用角度全栈生成器来创建Web应用程序。 I want to send a file data from nodejs server to display in the Front end.But data is sent in unformatted manner since i am receiving it in a variable( as a array of strings). 我想从nodejs服务器发送文件数据以显示在前端。但是数据以未格式化的方式发送,因为我以变量形式(以字符串数组形式)接收数据。 Plz. l tell me how to get the file data as it is (in the file at server )in the front end. 告诉我如何在前端获取文件数据(在服务器中的文件中)。

My nodejs code : 我的nodejs代码:

 function readstack() {
 fs = require('fs')
 fs.readFile('outstack.txt', 'utf8', function (err,data) {
 if (err) {
 return console.log(err);
 }
 console.log(data);
 res.send(data); 
 });
 }
 var stackend = setTimeout(readstack,30000);

My angular controller code : 我的角度控制器代码:

$http.get('/runtrace').success(function(response){
console.log("requested data");
$scope.output= response;

I am displaying in front end by : 我在前端显示:

 <div id="divoutput"> 
 {{output}}
 </div >

Did you try sending the file instead of reading using file system response.sendfile("yourText.txt"); 您是否尝试发送文件而不是使用文件系统response.sendfile(“ yourText.txt”);进行读取? ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM