首页 > 解决方案 > 在angularjs中读取表单输入的文件内容

问题描述

我的硬盘中有一个 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>

标签: javascriptjqueryangularjs

解决方案


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

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

推荐阅读