有条件的“多个"<输入类型=“文件">中的属性使用 AngularJS [英] Conditional "multiple" attribute in <input type="file"> with AngularJS

查看:18
本文介绍了有条件的“多个"<输入类型=“文件">中的属性使用 AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个上传表单字段,该字段可能允许也可能不允许用户选择多个文件.

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

我知道我可以这样做:

<input type="file" multiple ng-if="allow_multiple">
<input type="file" ng-if="!allow_multiple">

但是,我们知道这并不理想.

But, we know that is not ideal.

我试过了

<input type="file" ng-multiple="allow_multiple">

但这不起作用.

似乎 AngularJS 没有这样的 ngMultiple 指令,但是 无论如何每个人都在使用它(或者我错过了什么?)

It seems that AngularJS has no such ngMultiple directive, but everyone is using it anyway (or am I missing something?)

无论如何,实现这一目标的最佳方法是什么?

Anyway, what is the best way to accomplish that?

从到目前为止的答案来看,似乎没有很好的方法可以做到这一点.我在他们的追踪器上打开了这个问题,让我们看看我们得到了什么:-)https://github.com/angular/angular.js/issues/7714

From thw answers so far it really seems like there's no pretty way to do this. I opened this issue on their tracker, let's see what we get :-) https://github.com/angular/angular.js/issues/7714

推荐答案

我来到这个页面是为了解决与 Angular 2 相同的问题

I come to this page for same issue with Angular 2

最后修复如下:

<input type="file" 
    [accept]="extAccepts" 
    [multiple]="(maxFiles > 1)" />

注意:文件类型 (extAccepts) 和 maxFiles 都是从组件读取的@input() 来自用户.

Note: both file type (extAccepts) and maxFiles are reading from component as @input() from the user.

希望对某人有所帮助!

这篇关于有条件的“多个"&lt;输入类型=“文件"&gt;中的属性使用 AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆