<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>How to upload file in angularjs</title>
<script src="https://code.angularjs.org/1.3.14/angular.js"></script>
<script>
var app = angular.module('myApp', []);
app.controller('mycontroller', function($scope) {
alert(1);
$scope.onSelectFile = function($files) {
for (var i = 0; i < $files.length; i++) {
var $file = $files[i];
$upload.upload({
url: 'api/HomeControler/upload',
file: $file,
progress: function(e) {
// wait...
}
})
.then(function(data, status, headers, config) {
alert('file is uploaded successfully');
});
}
alert('file is uploaded successfully');
}
};
</script>
</head>
<body>
<div ng-controller="mycontroller">
<input type="file" ng-file-select="onSelectFile($files)" multiple>
</div>
<br/>
<div>
<a href="http://www.code-sample.com/" target="_blank">click for more...</a>
</div>
</body>
</html>
// Code goes here
/* Styles go here */