免责声明:我是AngularJS的C语言程序员,并且是非常的新手(更像是推入它),由于之前的人,我正在使用此代码结构。同样,有大约一百万个类似的问题,但不完全是我拥有的代码。所以潜水:
任务:我需要读取CSV文件,并从中获取一些数据。根据字段值,以特定颜色的HTML显示按钮(即,值> 4,然后显示绿色按钮,值
我做了什么:因此,我已经在NodeJS中使用fs读取了CSV文件,然后使用Factory将数据导入了AngularJS。
问题:在AngularJS中,我得到了一个Promise对象(控制台中的[object Object])。我需要访问在此对象中可以看到的值。我花了一个星期的大部分时间来看这个。
后端服务器-router.js
myRouter.route('/')
.get(function (req,res) {
var username = req.decoded.email;
var csvDir = path.join(dataPath,'mypath/' + username.substring(0,username.lastIndexOf("@")) + '.csv');
console.log('file path in myRouter:',csvDir);
fs.readFile(csvDir,'utf8',function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
res.json(data);
});
})
myFactory.js
'use strict';
angular.module('myApp')
.factory('myFactory',['$resource','baseURL',function ($resource,baseURL) {
return $resource(baseURL + "myRouter/",null,null);
}]);
AngularJS-controller.js
var initializeDisplay = function () {
console.log('Searching CSV file');
// TODO: http get request to read CSV file content
$scope.myData = FeatureFactory.get({},function () {
console.log($scope.myData);
});
// feedbackData.$promise.then(function (data) {
// console.log(data);
// },function (error) {
// console.error(data);
// })
console.log('Processing CSV file');
updateDisplay(); // To display correct color button in HTML
};
建议,非常欢迎您提供解决方案:)
T {0: "I",1: "D",2: ",",3: "S",4: "t",5: "o",6: "r",7: "y",8: ",9: "S",10: "i",11: "t",12: "u",13: "a",14: "t",15: "i",16: "o",17: "n",18: ",19: "T",20: "a",21: "s",22: "k",23: " ",24: "A",25: "c",26: "t",27: "i",28: "o",29: "n",30: ",31: "R",32: "e",33: "s",34: "u",35: "l",36: "t",37: ",38: "E",39: "y",40: "e",41: " ",42: "g",43: "a",44: "z",45: "e",46: ",47: "V",48: "o",49: "i",50: "c",51: "e",52: " ",53: "E",54: "n",55: "e",56: "r",57: "g",58: "y",59: ",60: "W",61: "M",62: "E",63: "I",64: "
",65: "↵",66: "1",67: ",68: "1",69: ",70: "4",71: ",72: "3",73: ",74: "2",75: ",76: "1",77: ",78: "2",79: ",80: "3",$promise: c,$resolved: true}
0: "I"
1: "D"
2: ","
3: "S"
4: "t"
5: "o"
6: "r"
7: "y"
8: ","
9: "S"
10: "i"
11: "t"
12: "u"
13: "a"
14: "t"
15: "i"
16: "o"
17: "n"
18: ","
19: "T"
20: "a"
21: "s"
22: "k"
23: " "
24: "A"
25: "c"
26: "t"
27: "i"
28: "o"
29: "n"
30: ","
31: "R"
32: "e"
33: "s"
34: "u"
35: "l"
36: "t"
37: ","
38: "E"
39: "y"
40: "e"
41: " "
42: "g"
43: "a"
44: "z"
45: "e"
46: ","
47: "V"
48: "o"
49: "i"
50: "c"
51: "e"
52: " "
53: "E"
54: "n"
55: "e"
56: "r"
57: "g"
58: "y"
59: ","
60: "W"
61: "M"
62: "E"
63: "I"
64: ""
65: "↵"
66: "1"
67: ","
68: "1"
69: ","
70: "4"
71: ","
72: "3"
73: ","
74: "2"
75: ","
76: "1"
77: ","
78: "2"
79: ","
80: "3"
$promise: c {$$state: {…}}
$resolved: true
__proto__: Object