环境同前篇随笔,lizi在这里po下js代码
演示地址
http://runjs.cn/detail/o4a55204
<script> 'use strict'; angular.module('app', ['angularFileUpload']) .factory("myService",function(){ var service={ files:function(){ var list= [ { fileName:'git指令.txt', size:3456, type:'', url:'http://oss.aliyun.com/sdfeweMDF' }, { fileName:'center.png', size:3456, type:'', url:'http://oss.aliyun.com/sdfeweMDF' } ]; return list; } }; return service; }) .controller('AppController', ['$scope', 'FileUploader','myService', function($scope, FileUploader,myService) { $scope.attachList=[]; var uploader = $scope.uploader = new FileUploader({ url: '/tianhe/file/uploadFile' }); uploader.onSuccessItem = function(fileItem, response, status, headers) { if(response.success){ $scope.attachList.push(response.data); } }; $scope.getDetail = function(){ var fileList = myService.files(); //$scope.attachList = myService.files; for(var i= 0,len=fileList.length;i<len;i++){ var dummy = new FileUploader.FileItem(uploader, { lastModifiedDate: new Date(), size: fileList[i].size, type: '', name: fileList[i].fileName }); dummy.progress = 100; dummy.isUploaded = true; dummy.isSuccess = true; uploader.queue.push(dummy); } } $scope.getDetail(); }]); </script>