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){
- var fd = new FormData();
- fd.append('file', file);
- $http.post(uploadUrl, fd, {
- transformRequest: angular.identity,
- headers: {'Content-Type': undefined}
- })
- .success(function(request){
- console.log(request);
- })
- .error(function(){
- });
- }
- }]);
- app.controller('myCtrl', ['$scope', 'fileUpload', function($scope, fileUpload){
- $scope.uploadFile = function(){
- var file = $scope.myFile;
- console.log('file is ' );
- console.dir(file);
- var uploadUrl = "html/api/v1/order/upload";
- fileUpload.uploadFileToUrl(file, uploadUrl);
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment