Introduction
In this article I will tell you how to create a file uploader using AngularJS.
You might have used a file uploader of ASP.NET, but what about a file uploader in AngularJS? You might have been using AngularJS in your application and if such type of application can be provided then it is just a bonus to us.
For providing this type of functionality Angular uses "angularFileUpload" and $upload.
Step 1
First of all you need to add an external Angular.js file to your application, "angular.min.js".
For this you can go to the AngularJS official site or can download my source code and then fetch it or you can click on this link to download it: ANGULARJS.
After downloading the external file you need to add this file to the Head section of your application.
<head runat="server">
<title></title>
<script src="angular.min.js"></script>
</head>
Step 2
Now after adding the external JS file the first thing you need to do is to add ng-app in the <HTML> Tag otherwise your application will not run.
<html ng-app xmlns="http://www.w3.org/1999/xhtml">
Now I will work on the JavaScript section of this application.
Write this code in the head section:
<script>
angular.module('mod', ['angularFileUpload']);
var x = ['$scope', '$upload', function ($scope, $upload) {
$scope.selectFile = function ($slctfl) {
$upload.upload({
url: 'my/upload/url'
})
}
}];
</script>
Here I have created angular.Module in which "mod" and "angularFileUpload" are defined, mod is the variable that will help to bind using the ng-app.
After this I have created a function "x", this function will be bound to the body section using the ng-controller directive. ng-app and ng-directive is among the most important directives when using AngularJS.
In this function I used a variable named "selectFile", in this function the upload directive is used with the property named URL. This URL will follow the path that will be provided by the user.
Just this much code is necessary to do our work of uploading a file for the user. Now we can move to the design part of this application.
Step 3
Write this code in the body section:
<body>
<form id="form1" runat="server">
<div ng-app="mod" ng-controller="x">
<input type="file" ng-file-select="selectFile($slctfl)" />
</div>
</form>
</body>




Aniruddha NargundPosted Jun 22, 2017, 12:17 AM
I m not able to find link to download source code
kalu singh raoPosted Aug 1, 2016, 9:40 AM
Nice