最近,我不得不使用 AngularJs 编写一个简单的上传器(可重用),同时将我的 API 放在不同的地方,最后使用blueimp jQuery File Uploader编写了一个并让 lil 对其进行了自定义。我认为分享这个可能会很棒,并希望在 AngularJs 学习中提高自己。(我已经添加了答案)
问问题
15968 次
1 回答
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()
)
上传者.directive
https://gist.github.com/sk8terboi87/5652187
上传.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>
于 2013-05-26T09:32:24.867 回答