Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive('fileModel', ['$parse', function ($parse) {
- return {
- restrict: 'A',
- link: 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]);
- });
- });
- }
- };
- }]);
- app.service('fileUpload', ['$http', function ($http) {
- this.uploadFileToUrl = function (file, uploadUrl) {
- debugger;
- var fd = new FormData();
- fd.append('file', file);
- //alert();
- debugger;
- console.log(fd);
- $http.post(uploadUrl, fd, {
- transformRequest: angular.identity,
- headers: { 'Content-Type': undefined }
- })
- .success(function () {
- })
- .error(function () {
- });
- }
- }]);
- $scope.uploadFile = function () { // This Function will Call when Click on upload button after selecting a file.
- var file = $scope.myFile;
- console.log(file);
- var uploadUrl = "http://localhost:25204/AdminOperation.asmx/Upload", //Url of webservice/api/server
- promise = fileUpload.uploadFileToUrl(file, uploadUrl);
- promise.then(function (response) {
- $scope.serverResponse = response;
- }, function () {
- $scope.serverResponse = 'An error has occurred';
- })
- };
Add Comment
Please, Sign In to add comment