2015-05-09 182 views
2

我有以下控制器:。角文件上傳dropzone不起作用

app.controller('DashboardController', ['$http', '$scope','$sessionStorage','$log','Session','api','FileUploader', function ($http, $scope, $sessionStorage,$log, Session, api,FileUploader) { 

    $scope.post = {user_id: $sessionStorage.user.user.id}; 


    var uploader = $scope.uploader = new FileUploader({ 
     url: 'js/controllers/upload.php' 
    }); 

    // FILTERS 

    uploader.filters.push({ 
     name: 'customFilter', 
     fn: function(item /*{File|FileLikeObject}*/, options) { 
      return this.queue.length < 10; 
     } 
    }); 

    // CALLBACKS 

    uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/, filter, options) { 
     console.info('onWhenAddingFileFailed', item, filter, options); 
    }; 
    uploader.onAfterAddingFile = function(fileItem) { 
     console.info('onAfterAddingFile', fileItem); 
    }; 
    uploader.onAfterAddingAll = function(addedFileItems) { 
     console.info('onAfterAddingAll', addedFileItems); 
    }; 
    uploader.onBeforeUploadItem = function(item) { 
     item.file.test = "gg"; 
     console.info('onBeforeUploadItem', item); 
    }; 
    uploader.onProgressItem = function(fileItem, progress) { 
     console.info('onProgressItem', fileItem, progress); 
    }; 
    uploader.onProgressAll = function(progress) { 
     console.info('onProgressAll', progress); 
    }; 
    uploader.onSuccessItem = function(fileItem, response, status, headers) { 
     console.info('onSuccessItem', fileItem, response, status, headers); 
    }; 
    uploader.onErrorItem = function(fileItem, response, status, headers) { 
     console.info('onErrorItem', fileItem, response, status, headers); 
    }; 
    uploader.onCancelItem = function(fileItem, response, status, headers) { 
     console.info('onCancelItem', fileItem, response, status, headers); 
    }; 
    uploader.onCompleteItem = function(fileItem, response, status, headers) { 
     console.info('onCompleteItem', fileItem, response, status, headers); 
    }; 
    uploader.onCompleteAll = function() { 
     console.info('onCompleteAll'); 
    }; 

    console.info('uploader', uploader); 
}]); 

具有以下HTML:

<div class="b-a b-2x b-dashed wrapper-lg bg-white text-center m-b" nv-file-over="" over-class="b-info" uploader="uploader"> 
           Base drop zone 

我的目標是我在Base drop zone

但是每當我試圖把東西放到放置項目儘快上傳它不需要該項目。任何人都可以看到什麼是做錯了嗎?

回答

3

只需在您的div上添加nv-file-drop=""即可。

<div class="b-a b-2x b-dashed wrapper-lg bg-white text-center m-b" nv-file-drop="" nv-file-over="" over-class="b-info" uploader="uploader">Base drop zone</div>

嘗試刪除就可以了文件,並檢查瀏覽器的控制檯被獲取調用的事件。
然後,您可以調用uploader.uploadAll(),例如onAfterAddingFile事件。