ng-file-upload提供两次错误消息

时间:2016-03-04 13:48:32

标签: javascript angularjs ng-file-upload

文件上传API:ng-file-upload

HTML

 <button ngf-select="vm.addPictures($files)" ngf-multiple="true" ngf-pattern="'.jpg,.png,.jpeg,.bmp'"
                            accept="image/*">
                        Select Files
                    </button>

Js

       //to add Pictures
       vm.addPictures = function ($files) {
              vm.upload = [];
              if ($files && $files.length) {
              //$files: an array of files selected, each file has name, size, and type
                  for (var i = 0; i < $files.length; i++) {
                          var $file = $files[i];
                            (function (index) {
                              vm.upload[index] = upload.upload({
                                 url: "/api/Picture/AddPictures",
                                 method: "POST",
                                 data: {},
                                        file: $file
                                    }).progress(function () {
                                    }).success(function (data) {
                                        vm.pictureList.push({
                                            id: vm.pictureList.length + 1,
                                            url: '/common/pictures/' + data.newImageName,
                                            note: '',
                                            isSelected: true,
                                        });

                                    }).error(function () {
                                    });
                                })(i);
                            }
                 } else {
  abp.message.error('Invalid file format', 'Error');//this is the error msg which it fires twice.
                 }
              };

问题:当用户选择了错误的格式时,它会按预期显示错误消息。但之后,当用户尝试再次选择图像时,只需按下&#34;选择&#34;按钮,即使没有选择图像,它再次显示相同的错误消息。你能告诉我如何解决这个问题吗?谢谢。

更新:当我选择错误的文件类型时,它看起来像这样......

enter image description here

0 个答案:

没有答案