I'm trying to load an image from the input[type=file] to the image on a page. Is it possible to do it without uploading a file to the database?
Asked
Active
Viewed 185 times
1 Answers
3
Here is a solution for this, i've got with a help of Ravi(thanks to him).
1 Create a "fileURL" variable. How to do it
2 On image set "src" attribute with value of "{{fileURL}}". How to do it
3 Click on "file" and add "change" evet -> run typescript, with code How to do it:
//event.target.firstChild - is an input.
let file = event.target.firstChild.files[0];
if(file)
this.fileURL = URL.createObjectURL(file);

John802
- 71
- 4