最近,我不得不使用AngularJs编写一个简单的上传器(可重用),同时,将我的API保存在单独的位置,最后使用blueimp jQuery File Uploader编写一个并使lil自定义它。我认为分享这个并希望在AngularJs中学习自我提高可能会很棒。 (我已经添加了答案)
答案 0 :(得分:0)
http://codelikeapoem.com/2013/05/angularjs-tutorial-4-file-upload-using.html (您可以下载整个代码)
App.Coffee
@angTut = angular.module("angTut", ['LocalStorageModule', 'ngResource', 'uploaderComponent']);
@angTut.constant('uploadServiceUrl', 'http://192.168.0.2/api/index.php')
todos_uploader_controller.coffee
"use strict"
@angTut.controller('TodosUploadController', (
$scope, uploadService
) ->
$scope.uploadLayer = (e, data, process) ->
$scope.uploadReturn = uploadService.process(e, data, process)
$scope.uploadReturn = uploadService.initialize()
)
uploader.directive
https://gist.github.com/sk8terboi87/5652187
upload.html
<div class="control-group">
<input id="testUpload" type="file" fileupload name="files[]" uploadurl="uploadReturn.uploadurl" done="uploadLayer(e, data, 'done')" fail="uploadLayer(e, data, 'fail')" progress="uploadLayer(e, data, 'progress')">
<div class="well" ng-show="uploadReturn.status">
{{uploadReturn.message}}
<div ng-show="!uploadReturn.error">
<p class="label label-info">File: {{uploadReturn.successData.name}}</p>
<p><a href="{{uploadReturn.successData.fullUrl}}" target="_blank">View file</a></p>
</div>
</div>
</div>