How to make FileReader work with Angular2!!
When reading a file from client side with Angular2 and Typescript,
I try to use FileReader in this way:
var fileReader = new FileReader();
fileReader.onload = function(e) {
console.log("run fileReader.onload");
// ......
}
But it doesn't work at all, this 'fileReader.onload' function will never be called.
Really need a solution for reading files, please help. Thanks
Check this from an online IDE:
First you have to specify the target of the change event on input form in template:
As you can see I binded a
changeListener()method to(change)event. My implementation of class:Listener is passing file from event to
readThismethod. Read this have implemented it's ownFileReader. You can also define FileReader in component instead in function.