2017-12-27 79 views
0

我想提交一個文件,我輸入了一次,我點擊了系統窗口上的文件上傳確定,但我不知道該怎麼做......這就是我'已經這樣做的遠:導入文件並在彈出窗口關閉時提交AngularJS

<input type="file" id="file-input" style="display:none" /> 

<button class="btn pull-right" ng-click="submitCashierFile()">Import</button> 

JS:

$scope.submitCashierFile = function() { 
     angular.element('#file-input').trigger('click'); 

// I should have something like this next i guess? 

$scope.cashierfile.upload = Upload.upload({ 
       url: config.baseAddress + 'test/uploadCashierExcel', 
       data: { file: $scope.cashierfile } 
      }); 

      $scope.cashierfile.upload.then(function (response) { 
       $timeout(function() { 
        $scope.cashierfile.result = response.data; 
        toastService.success('You have added .xlsx'); 
       }); 
      }, function (response) { 
       toastService.error(response); 
      }); 

    }; 

所以我通過靶向點擊,打開模式選擇文件,對我來說,問題是如何提交上單擊該模式的確定。有什麼建議麼?

+0

如果你用[ng-file-upload](https://github.com/danialfarid/ng-file-upload)沒關係,我會建議去那。它很容易實現你想要使用這個。 – Ashish

回答

0

你的問題對我來說不是很清楚,但我會根據我的理解給它一個基礎。

您應該映射控件的onchange事件。這會在選擇要上傳的文件後立即激活。 然後你應該做文件的實際上傳。

當我需要完成這項任務時,我放棄使用Angular並轉而使用HTML5文件上傳機制。那一個正如你所描述的那樣工作...