jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

AngularJS event handling

Open Bochenski opened this issue 13 years ago • 2 comments

When using the plugin with jquery.fileupload-angular.js to bind to events (i.e. fileuploadsubmit) I don't think it's possible to cancel the event from within the calling app.

So modyfying app.js to add a listener for the 'fileuploadsubmit' event

.controller('DemoFileUploadController', [
  '$scope', '$http', '$filter', '$window',
    function ($scope, $http, $filter, $window) {
       $scope.loadingFiles = true;
       $scope.options = {
          url: url,
       };
      $http.get(url)
            .then(
                function (response) {
                   $scope.loadingFiles = false;
                   $scope.queue = response.data.files || [];
                },
                function () {
                   $scope.loadingFiles = false;
                }
            );
       $scope.$on('fileuploadsubmit', function(e, data) {
           console.log('This is reached correctly, so the event fires fine');
           return false; //this is not passed back to fileUpload
        });
     }
  ])

It makes sense to me that this doesn't work, as jquery.fileupload-angular.js simply calls $scope.$emit(e.type, data). But I wonder if there is a way to make this work, I'm concerned also that anything else you do inside $scope.$on is not guaranteed to run at the correct point in the fileUpload event lifecycle

Bochenski avatar Jul 17 '13 10:07 Bochenski

You can now prevent default event actions in Angular scope listeners, too:

$scope.$on('fileuploadsubmit', function (e, data) {
    e.preventDefault();
});

blueimp avatar Jul 17 '13 17:07 blueimp

Thanks for the super quick response, this is great.

Bochenski avatar Jul 18 '13 08:07 Bochenski