2014-10-03 76 views
2

我試圖使用https://github.com/danialfarid/angular-file-upload但顯然我不能訪問該文件

我的HTML

<img 
    src = "{{ userPhotoUrl }}" 
    alt = "" 
    class = "img-circle img-responsive" 
    accept = "image/*" 
    data-multiple = "false" 
    ng-file-select = "onFileSelect($file)" 
> 

我Coffescript :

$scope.onFileSelect = ($file) -> 
    console.log $file 
    $scope.upload = $upload.upload 
    url : '/api/upload/photo' 
    file : $file 
    method : 'POST' 
    .progress (e) -> 
    console.log 'percent' + parseInt 100.0 * e.loaded/e.total 
    .success (data, status, headers, config) -> 
    console.log data, status, headers, config 

我只是得到undefinedconsole.log($file)

什麼可能是錯誤的?我試圖把同樣的邏輯在

<input type="file" ng-file-select="onFileSelect($file)"> 

,但我得到了相同的結果

+0

'$ files' not'$ file' – przno 2014-10-03 14:02:08

回答

1

在HTML變化$file$files

ng-file-select = "onFileSelect($files)" 

這東西在文件上傳暴露,就像同樣也可以使用$last$first連同ng-repeat

+0

呃......就是這樣,謝謝! – 2014-10-03 15:23:33