Conditional “multiple” attribute in <input type=“file”> with AngularJS

前端 未结 8 2237
感情败类
感情败类 2021-01-11 18:02

I need an upload form field that may or may not allow the user to select more than one file.

I know I can do something like:



        
8条回答
  •  猫巷女王i
    2021-01-11 18:38

    Besides the difficulty of doing this there is also the issue that some browser will not evaluate multiple="false" (Safari 8 on file input for ex). So the multiple attribute needs to be conditionally written.

    I would wrap your html in a directive and conditionally apply the attribute within the directive such as:

    var input = elem.find('input');
    if(condition)
      input.attr('multiple', 'true');
    

    Where the condition could be any directive attribute.

提交回复
热议问题