简体   繁体   中英

consolidate file choose and upload in one line in angularJs only

Currently, I choose the file and upload using 2 different buttons as follows:

<input type="file" file-model="myFile" />
<button ng-click="uploadFile()">upload me</button>

Is it possible to choose the file and upload in 1 single button?

I tried the following but did not work.

<input type="file" file-model="myFile" onchange="uploadFile()" />

You can use ng-file-select like this:

<input type="file" ng-model="fname" ng-file-select="uploadFile($files)">

Inside your controller, you'll get object:

$scope.uploadFile = function($files) {
    var file = $files[0];
    console.log(file);
}

More details:
http://blog.gitbd.org/file-upload-by-angular-and-php/

try this

<input type="file" file-model="myFile" onChange="uploadFile()" />

 <!DOCTYPE html> <html> <head> <title>Page Title</title> <script> function uploadFile(){ alert("function accessed"); } </script> </head> <body> <input type="file" file-model="myFile" onChange="uploadFile()" /> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM