Git Product home page Git Product logo

Comments (8)

nervgh avatar nervgh commented on June 18, 2024

Hi

1, 3. You can disable the submit button until will not be filled required fields.
2. You can get a response as shown in the code below.

uploader.bind('success', function (event, xhr, item, response) {}); // response
uploader.bind('error', function (event, xhr, item, response) {}); // response

https://github.com/nervgh/angular-file-upload#events
4. Please, update your module to last version

from angular-file-upload.

bettysteger avatar bettysteger commented on June 18, 2024

ok i've updated the module to 0.3!

  1. i know that i can disable it, but i'm testing server-side validation..
  2. i added the response like you said, but it triggers success twice (the console.log is outputed twice)

new code:

    // successful upload
    uploader.bind('success', function (event, xhr, item, response) {
      console.log('success')
      uploader.clearQueue();

      successCallback(response);
    });

    // unsuccessful upload
    uploader.bind('error', function (event, xhr, item, response) {
      errorCallback(response);
    });

workflow:

  1. unsuccessful upload = error
  2. then successful upload = success but 2x

from angular-file-upload.

nervgh avatar nervgh commented on June 18, 2024
  1. then successful upload = success but 2x

You have two event listeners, probably.

You can get the number of listeners so:

uploader.bind('success', function (event, xhr, item, response) {
    var listeners = this.scope.$$listeners[this._timestamp+':success'];
    console.info('listeners.length', listeners.length); // 1 - if there is one listener
});

from angular-file-upload.

bettysteger avatar bettysteger commented on June 18, 2024

hmm that's strange, normally i have 1 listener, and just when I do what causes the problem I got 2!

do you know how I can solve this?

from angular-file-upload.

bettysteger avatar bettysteger commented on June 18, 2024

i did this dirty hack and it works now:

      var listeners = this.scope.$$listeners[this._timestamp+':success'];
      if(listeners.length > 1) {
        listeners.pop();
      }

from angular-file-upload.

nervgh avatar nervgh commented on June 18, 2024

do you know how I can solve this?

Add one event listener =)

You can test this so

console.log('new listener', uploader.scope.$$listeners[uploader._timestamp+':success'].length); // 1
uploader.bind('success', function (event, xhr, item, response) {

from angular-file-upload.

awerlang avatar awerlang commented on June 18, 2024

It's better to bind to events just at initialization.

Startup:

// successful upload
uploader.bind('success', function (event, xhr, item) {
  console.log("success")
  uploader.clearQueue();

  var response = angular.fromJson(xhr.response);
  successCallback(response);
});

// unsuccessful upload
uploader.bind('error', function (event, xhr, item) {
  var response = angular.fromJson(xhr.response);
  errorCallback(response);
});

Submit:

if(uploader.queue.length) {
  var firstItem = uploader.queue[0];
  uploader.uploadItem(firstItem);
}

from angular-file-upload.

vzabaznov avatar vzabaznov commented on June 18, 2024

try to check your $routeProvider, may be your routing execute your controller twice

from angular-file-upload.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.