[Angular2]How to use filereader.load with Angular2??

2,502 views
Skip to first unread message

ran xian

unread,
Jun 12, 2015, 1:14:51 PM6/12/15
to ang...@googlegroups.com
[Angular2]How to use filereader.load with Angular2 and Typescript?

Try to read a file from client side with Angular2 and Typescript.

But when I try something like: 

fileReader.onload = function(e) {
  ......
}

It doesn't work, this function will never be called. (which works in normal html+javascript.)

Need a solution here, many thanks!!

ran xian

unread,
Jun 14, 2015, 9:52:53 AM6/14/15
to ang...@googlegroups.com

I finally find a way to build a online example with Typescript.

Check this from an online IDE:

preview:

editor:

Again, need a solution for this. Thanks




在 2015年6月13日星期六 UTC+8上午1:14:51,ran xian写道:

ran xian

unread,
Jun 14, 2015, 12:27:33 PM6/14/15
to ang...@googlegroups.com


Here are some examples can easily play with:

First of all:  FileRead with pure javascript, works fine:
http://codepen.io/butaixianran/pen/gpxpww

With angular2, ES5 javascript (generate by TypeScript), doesn't work:
http://plnkr.co/edit/1MTFbVCKGGOU9XPcNVit?p=preview

With angular2 and typescript at codepen:
(Typescript with .t.d file won't work at codepen, following link just show you the TS source code)
http://codepen.io/butaixianran/pen/XbabaO

Online IDE (c9.io), sandbox with Angular2 and TypeScript, doesn't work:
(can login with github account)
https://ide.c9.io/butaixianran/angular2

Preview offered by this online IDE:
https://angular2-butaixianran.c9.io/src/index.html

Need a solution, thanks



在 2015年6月14日星期日 UTC+8下午9:52:53,ran xian写道:
Reply all
Reply to author
Forward
0 new messages