0

I've made a directive for file upload. When I'm trying to upload only the same file, the dialog which is after uploading doesn't show. I don't know how to figure it out to open next dialog every time.

export function fileReaderDirective() {
  'ngInject';

  let directive = {
    restrict: 'A',
    require: '?ngModel',
    link: fileReaderLink
  };

  return directive;
}

function fileReaderLink(scope, element, attrs, ngModel){
  if( attrs.type === 'file' && ngModel ) {
    element.bind('change', function(event) {
      scope.$apply(function() {
        ngModel.$setViewValue(event.target.files);
      });
    });
  }
}

<input name="file" id="image-upload" type="file" ng-model="file" filereader/>
Przemek
  • 27
  • 3

1 Answers1

0

This is standard behaviour. Change event does not fire when you choose the same file again since its path does not change. Its pure HTML related, it has nothing to do with angular. There are some similiar questions (answers) you can relate to:

Javascript file input onchange isn't triggered when they select a file with the same name
How to detect input type=file “change” for the same file?

Community
  • 1
  • 1
B.Gen.Jack.O.Neill
  • 8,169
  • 12
  • 51
  • 79
  • I figured out this way with 'click' but nothing happened. I had to do something wrong. Thank you! – Przemek Sep 06 '16 at 20:26