前言
本文主要给大家介绍了关于Angular.js中上传指令ng-upload的基本使用,分享出来供大家参考学习,下面话不多说,来一起看看详细的介绍:
Angular上传指令ng-upload的基本使用,包括上传文件,图片,以及图片和视频在线预览,非常强大。ng-upload有两种用法,一种是选择上传文件,仅仅存起来,还有一种就是选择之后,立刻出发一个上传函数,虽然这个函数可以不做http upload的操作。
1.首先包含库文件
<script src="/UploadFiles/2021-04-02/angular.min.js">2.只选择,有submit上传
Upload on form submit or button click <form ng-app="fileUpload" ng-controller="MyCtrl" name="form"> Single Image with validations <div class="button" ngf-select ng-model="file" name="file" ngf-pattern="'image/*'" ngf-accept="'image/*'" ngf-max-size="20MB" ngf-min-height="100" ngf-resize="{width: 100, height: 100}">Select</div> Multiple files <div class="button" ngf-select ng-model="files" ngf-multiple="true">Select</div> Drop files: <div ngf-drop ng-model="files" class="drop-box">Drop</div> <button type="submit" ng-click="submit()">submit</button> </form>3.选择之后,立马上传
Upload right away after file selection: <div class="button" ngf-select="upload($file)">Upload on file select</div> <div class="button" ngf-select="uploadFiles($files)" multiple="multiple">Upload on file select</div> Drop File: <div ngf-drop="uploadFiles($files)" class="drop-box" ngf-drag-over-class="'dragover'" ngf-multiple="true" ngf-pattern="'image/*,application/pdf'">Drop Images or PDFs files here</div> <div ngf-no-file-drop>File Drag/Drop is not supported for this browser</div>4.upload模块还能显示图片预览
Image thumbnail: <img ngf-thumbnail="file || '/thumb.jpg'"> Audio preview: <audio controls ngf-src="/UploadFiles/2021-04-02/file">这个里面注意了:这里面的file不是图片路径,而是,
ngf-select ng-model="file" name="file"
操作的时候,或者ngf-select="upload($file)
传给调用函数的那个file对象总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持