加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular1 打开文件 并另存为(文件的读取与写入)

发布时间:2020-12-17 07:04:25 所属栏目:安全 来源:网络整理
导读:最近有个需求,在页面上有个按钮可以选取文件然后在导出到其它地方, 说明白点就是文件的读取与写入,下面是例子(例子中用到了fileSave.js github地址:https://github.com/eligrey/FileSaver.js) 首先引入fileSave.js? ? import ‘../../../lib/file-save

最近有个需求,在页面上有个按钮可以选取文件然后在导出到其它地方,

说明白点就是文件的读取与写入,下面是例子(例子中用到了fileSave.js github地址:https://github.com/eligrey/FileSaver.js)

首先引入fileSave.js? ?

import ‘../../../lib/file-saver/dist/FileSaver.min.js‘;

html:

<input type="file" id="fileUpload" value="选择文件" mce_style="display:none" onchange="angular.element(this).scope().fileChoose(this)" >
<button ng-click="chaunshu()" class="btn btn-default">转移</button>

?

script:

$scope.fileChoose = (ele) => {    $scope.files = ele.files[0];//读取文件信息};$scope.chaunshu = () => {    if($scope.files == ‘‘ || $scope.files == undefined ){        layer.alert(‘请先选择文件‘,{closeBtn: false,icon: 2},index => {            layer.close(index);        });    }else {        let filename = $scope.files.name;        let type = $scope.files.type;        let blob = new Blob([$scope.files],{type: type}); //[$scope.files]要保存的文件  {type:保存文件类型}        saveAs(blob,filename);//保存    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读