2016-01-30 100 views
0

我試圖在我的小應用程序中實現angular-file-upload,但沒有獲得太大的成功。無法使用角度文件上傳來上傳文件

以我的index.html,我已正確添加參考

<script src="/Scripts/angular-file-upload.min.js"></script> 

HTML

<div class="form-group"> 
     <input type="file" name="FileUpload" class="btn btn-default btn-block" data-ng-file-select="onFileSelect($files)"> 
</div> 

這是我的控制器代碼。

//On select file 
$scope.onFileSelect = function ($files) { 
    $scope.selectedFile = null; 
    if ($files.length > 0) { 
      $scope.selectedFile = $files[0]; 
      $scope.attachment = { 
       lastModified: $scope.selectedFile.lastModified, 
       lastModifiedDate: $scope.selectedFile.lastModifiedDate, 
       name: $scope.selectedFile.name, 
       size: $scope.selectedFile.size, 
       type: $scope.selectedFile.type, 
       webkitRelativePath: $scope.selectedFile.webkitRelativePath 
      }; 
    } 
}; 

問題: 當我瀏覽和選擇文件時,則觸發該功能/被叫和$文件始終保持爲空。

我在這裏失蹤了什麼?

+0

您是否將模塊包含在角度應用配置中?例如。 'angular.module(「YourApp」,[「angularFileUpload」])' – tanenbring

+0

是的,我加了。但仍然是這種情況。你能分享一個示例教程嗎? – simbada

回答

0

有多個指令名稱angular-file-upload。你可以發佈鏈接到你正在使用的指令嗎?