Guest User

Untitled

a guest
Mar 30th, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. app.directive('fileModel', ['$parse', function ($parse) {
  2. return {
  3. restrict: 'A',
  4. link: function(scope, element, attrs) {
  5. var model = $parse(attrs.fileModel);
  6. var modelSetter = model.assign;
  7.  
  8. element.bind('change', function(){
  9. scope.$apply(function(){
  10. modelSetter(scope, element[0].files[0]);
  11. });
  12. });
  13. }
  14. };
  15. }]);
  16. app.service('fileUpload', ['$http', function ($http) {
  17. this.uploadFileToUrl = function(file, uploadUrl){
  18. var fd = new FormData();
  19. fd.append('file', file);
  20. $http.post(uploadUrl, fd, {
  21. transformRequest: angular.identity,
  22. headers: {'Content-Type': undefined}
  23. })
  24. .success(function(request){
  25. console.log(request);
  26. })
  27. .error(function(){
  28. });
  29. }
  30. }]);
  31. app.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
  32. $scope.uploadFile = function(){
  33. var file = $scope.myFile;
  34. console.log('file is ' );
  35. console.dir(file);
  36. var uploadUrl = "html/api/v1/order/upload";
  37. fileUpload.uploadFileToUrl(file, uploadUrl);
  38. };
  39.  
  40. }]);
Advertisement
Add Comment
Please, Sign In to add comment