0
  • 我正在使用danialfarid/ng-file-upload插件,我将 ngf-select 指令设置为 .doc,.pdf 扩展名。它工作正常。
    • 问题是如果用户选择 .png 或 jpg 文件,我想向用户显示不接受此文件类型的警告框。提前感谢您。
4

1 回答 1

0

使用这样的东西(没有测试过代码,但你可以明白):

HTML

<button type="button" ngf-select="set($file)" ngf-pattern="'.doc,.pdf'">Select file...</button>

JS(在你的控制器中)

$scope.set = function(file) {
    if(file 
        && file.$error
        && (file.$errorParam.indexOf('.png') > -1
            || file.$errorParam.indexOf('.jpg') > -1)
    ){
        alert('file type is not allowed ):');
    }
}

或者您可以使用input带有 的元素accept,在大多数浏览器中甚至不允许用户选择其他文件类型:

<input type="file" ngf-select accept=".doc,.pdf"></input>
于 2015-08-21T19:37:57.653 回答