File input - Retrieving the file

2,601 views
Skip to first unread message

Andy Joslin

unread,
May 7, 2012, 10:44:48 AM5/7/12
to ang...@googlegroups.com
Hi,

I am having trouble getting the chosen file from a file input.

Here is the JSFiddle: http://jsfiddle.net/ADukg/11/

Nothing is shown when I pick a file.

Marcello Nuccio

unread,
May 8, 2012, 4:45:37 AM5/8/12
to ang...@googlegroups.com
File input type, is not implemented in angular [1]. You can use a dirty hack [2], or patch angular [3]. I do patch angular, but I don't know how to write tests for it :-(.

 [1]: https://github.com/angular/angular.js/issues/757
 [2]: http://jsfiddle.net/marcenuc/ADukg/49/
 [3]: https://github.com/angular/angular.js/issues/757#issuecomment-5242739

HTH

Andy Joslin

unread,
May 8, 2012, 8:42:27 AM5/8/12
to ang...@googlegroups.com
HI marcello, thanks.  I'll probably use the hack for now.

Marcello Nuccio

unread,
May 9, 2012, 5:51:25 AM5/9/12
to ang...@googlegroups.com
Actually I've posted the wrong hack. Here's the cleaner one (IMHO):

    http://jsfiddle.net/marcenuc/ADukg/89/

D. Zen

unread,
May 22, 2012, 11:16:10 AM5/22/12
to ang...@googlegroups.com
Thanks Marcello,
  Here's an update to allow multiple files:


zen

Marcello Nuccio

unread,
May 22, 2012, 11:34:02 AM5/22/12
to ang...@googlegroups.com
Glad it helped... as I've said, the problem is: how to test it?

Actually, I'm using the patch [1], not the hack. The patch also supports `accept` attribute, with some quirks due to browsers differences... maybe we should use a custom attribute, for example `ng-accept`...

Daniel Zen

unread,
May 22, 2012, 11:39:18 AM5/22/12
to ang...@googlegroups.com
I like the concept of a patch, but I would prefer it to be documented and rolled into the main branch.
In the meantime, this is an acceptable hack. If I get a chance, I will look at how to test your patch.

Thanks again,
zen

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/clreXOkbx3sJ.

To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

David Brunner

unread,
May 25, 2012, 11:44:44 PM5/25/12
to ang...@googlegroups.com
Marcello, Zen, this was extremely helpful.  Thank you very much for sharing your solution!

David
Reply all
Reply to author
Forward
0 new messages