181
rated 0 times
[
186]
[
5]
/ answers: 1 / hits: 67297
/ 6 Years ago, wed, may 23, 2018, 12:00:00
I have this code to show the image preview before uploading it. However I am working with Angular 5 so I have a .ts
file instead of a .js
one. How can I do the same in Angular 5? I also want to show the image in all browsers.
My HTML:
<input type='file' onchange="readURL(this);"/>
<img id="blah" src="http://placehold.it/180" alt="your image"/>
My CSS:
img {
max-width:180px;
}
input[type=file] {
padding: 10px;
background: #2d2d2d;
}
My JavaScript:
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
document.getElementById('blah').src=e.target.result
};
reader.readAsDataURL(input.files[0]);
}
}
More From » angular