第二次上传同一个文件并不会打开新的对话窗口

时间:2016-09-06 20:14:41

标签: javascript angularjs

我已经制定了文件上传指令。当我尝试仅上传同一个文件时,上传后的对话框不会显示。我不知道如何弄清楚每次打开下一个对话框。

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/>

1 个答案:

答案 0 :(得分:0)

这是标准行为。当您再次选择同一文件时,更改事件不会触发,因为其路径不会更改。它与纯HTML相关,它与angular无关。您可以参考以下类似的问题(答案):

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?

相关问题