FILE的用法错误-alasql angular2

时间:2018-09-12 12:22:28

标签: javascript angular typescript ionic-framework alasql

我正在尝试导入CSV并将结果存储在数组中。我正在关注这个jsfiddle

print('AlaSQL v'+alasql.version)
print('Please upload txt, json, csv, tsv, tab, xlsx, xls or html file to see the content')

loadFile = function(event) {
	alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(data){
		print(data)
	});
}

function print(x){
    document.getElementById('output').textContent += JSON.stringify(x,  null, '\t')+"\n";
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.8.0/xlsx.full.min.js"></script>

<script src="https://rawgit.com/agershun/alasql/develop/dist/alasql.js"></script>
<input id="readfile" type="file" onchange="loadFile(event)"/>
<xmp id="output"></xmp>

当我尝试在Angle 2中使用相同的代码时,出现以下错误

  

错误:FILE()函数使用错误

我已经安装了alasql npm软件包,下面是我的home.htmlhome.ts代码:

home.html

<input id="readfile" type="file" (change)="loadFile(event)"/>

home.ts

  loadFile = function(event) {
    alasql('SELECT * FROM FILE(?,{headers:true})',[event],function(data){
       console.log(data,"data");
     });
}

选择并上传文件时,出现此错误,请参见下面的屏幕截图:

enter image description here

0 个答案:

没有答案