在angularjs的表单输入中读取文件内容

时间:2019-01-25 16:55:22

标签: javascript jquery angularjs

我的HDD中有一个JSON文件,当使用输入字段选择该文件时,如何读取该文件的内容?

我必须阅读内容并将内容作为某些API中的数据发送!

我需要这样的东西:

<input type="file" id="dashboardExportedFile">
<button type="button" ng-click="importDashboard">Import</button>
<script>
  $scope.importDashboard = function (
    var content = $("#dashboardExportedFile").content
    console.log(content);
  };
</script>

1 个答案:

答案 0 :(得分:1)

我认为您需要一个Filereader。按照我的链接查看.txt文件的工作示例。希望你可以使用它: [JSFiddle] [1]

[1]: http://jsfiddle.net/alexsuch/6aG4x/