This should do what you want:
<input type='file' (change)="readUrl($event)">
<img [src]="url">
readUrl(event:any) {
if (event.target.files && event.target.files[0]) {
var reader = new FileReader();
reader.onload = (event: ProgressEvent) => {
this.url = (<FileReader>event.target).result;
}
reader.readAsDataURL(event.target.files[0]);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…