我试图使用带有一个文本框的角度材料mdDialog打开对话框并下拉字段但是一旦打开它就无法访问外部范围数据。 我的代码是
$scope.ouetButton=function(){
$mdDialog.show({
scope: $scope.$new(),
templateUrl: "printDialog.html"
});
// Button click in templete
$scope.closeDialog = function(sheetout, reason, teststartTime) {
$mdDialog.hide();
var sheets = $scope.sheets;
console.log("i got this value undifined ",sheets );
}
}
如果我使用像
这样的参数$scope.ouetButton=function(){
$mdDialog.show({
scope: this,
templateUrl: "printDialog.html"
});
// Button click in templete
$scope.closeDialog = function(sheetout, reason, teststartTime) {
$mdDialog.hide();
var sheets = $scope.sheets;
console.log("i got this value fine",sheets );
}
}
比获得工作表的价值但是在关闭后我无法再次点击
$scope.ouetButton
答案 0 :(得分:2)
要获取JSON字符串(例如,从读取文件)到实际的JavaScript对象,请使用JSON.parse(string)
。这是一个例子:
fs.readFile('data.txt', function(err, data) {
if (err) throw err;
var array = JSON.parse(data); // converts the JSON string into an actual object/array
// use array as you did in your question...
});
奖励:使用for...of
loop处理数组的每个元素:
for (var obj of array) {
console.log(obj.date_created);
// etc.
}
请注意,这仅在ECMAScript 6之后可用,但由于您使用的是Node.js,这不应该是一个问题。
答案 1 :(得分:0)
此文件包含VALID JSON STRING
,因此只需读取文件并执行JSON.parse(),然后您就可以使用JSON对象执行任何其他操作。