0

I've made a Angular directive to warp the a file upload input.

directive('ngFile', function () {
    return {
        link: function (scope, element, attrs) {
            var button = element.find('button[data-fileInputButton]');
            var inputElement = element.find('input[type="file"]');        

            var updateModel = function (evt) {
                scope.$apply(function () {
                    scope.files = evt.target.files;
                    if (scope.startUpload) {
                        scope.startUpload();
                    }

                    evtl.target.files = [];
                });
            }

            inputElement.bind('change', updateModel);

            button.click(function () {
                var input = element.find('input[type="file"]');
                input.click();
            });
        }
    } 
});

When I click and select a file, everything is OK. However, when I select the file again, the event is not fired. It is only fired when I select another file. Why is this happening?

1
  • because the event is triggered when the input changes. Commented May 12, 2015 at 12:27

1 Answer 1

2

The change is listening to the value and not to the files.

you need to do:

evt.target.value = "";

Good luck :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.