AngularJS Tutorial
AngularJS Applications
AngularJS Useful Resources
Selected Reading
- AngularJS - Internationalization
- AngularJS - Custom Directives
- AngularJS - Dependency Injection
- AngularJS - Services
- AngularJS - Scopes
- AngularJS - Views
- AngularJS - AJAX
- AngularJS - Includes
- AngularJS - Forms
- AngularJS - Modules
- AngularJS - HTML DOM
- AngularJS - Tables
- AngularJS - Filters
- AngularJS - Controllers
- AngularJS - Expressions
- AngularJS - Directives
- AngularJS - First Application
- AngularJS - MVC Architecture
- AngularJS - Environment Setup
- AngularJS - Overview
- AngularJS - Home
AngularJS Applications
- AngularJS - Lastfm Application
- AngularJS - Leaflet Application
- AngularJS - Timer Application
- AngularJS - Weather Application
- AngularJS - Share Application
- AngularJS - Maps Application
- AngularJS - Chart Application
- AngularJS - Translate Application
- AngularJS - Cart Application
- AngularJS - Drag Application
- AngularJS - Search Tab
- AngularJS - Order Form
- AngularJS - Switch Menu
- AngularJS - Nav Menu
- AngularJS - In-line Application
- AngularJS - Upload File
- AngularJS - Login Application
- AngularJS - Bootstrap Application
- AngularJS - Notepad Application
- AngularJS - ToDo Application
AngularJS Useful Resources
- AngularJS - Discussion
- AngularJS - Useful Resources
- AngularJS - Quick Guide
- AngularJS - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
AngularJS - Upload File
AngularJS - Upload File
We are providing an example of Upload File. To develop this app, we have used HTML, CSS and AngularJS. Following example shows about how to upload the file using AngularJS.
<html> <head> <script src = "https://ajax.googleapis.com/ajax/pbs/angularjs/1.3.14/angular.min.js"> </script> </head> <body ng-app = "myApp"> <span ng-controller = "myCtrl"> <input type = "file" file-model = "myFile"/> <button ng-cpck = "uploadFile()">upload me</button> </span> <script> var myApp = angular.module( myApp , []); myApp.directive( fileModel , [ $parse , function ($parse) { return { restrict: A , pnk: function(scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind( change , function() { scope.$apply(function() { modelSetter(scope, element[0].files[0]); }); }); } }; }]); myApp.service( fileUpload , [ $https: , function ($https:) { this.uploadFileToUrl = function(file, uploadUrl) { var fd = new FormData(); fd.append( file , file); $https:.post(uploadUrl, fd, { transformRequest: angular.identity, headers: { Content-Type : undefined} }) .success(function() { }) .error(function() { }); } }]); myApp.controller( myCtrl , [ $scope , fileUpload , function($scope, fileUpload) { $scope.uploadFile = function() { var file = $scope.myFile; console.log( file is ); console.dir(file); var uploadUrl = "/fileUpload"; fileUpload.uploadFileToUrl(file, uploadUrl); }; }]); </script> </body> </html>
Result
Open above saved code file in a web browser. See the result.
Advertisements