I have an img tag and an input type file,
Functionality
The functionality is i will input one jpg file using input type file, i need to show this image in the image tag.
How is it possible in angular 2 ?
My tries I tried to get the file path on change event of input button and assign it to the src of image file.
Tried to solve it using an external js file.
but both these tries are failure, whats the solution for this.
Code
HTML
<img [src]="imagePath" width="100px">
<input type="file" multiple (change)="onUpload(input)" #input >
Component.ts
import { Component, OnInit, NgModule } from '@angular/core';
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
})
export class FormComponent implements OnInit {
//DECLARATION
imagePath:string;
constructor() {
this.onInitial();
}
ngOnInit() {}
onInitial(){
this.imagePath="../../assets/images/1.jpg"
}
onUpload(event){
console.log(event);
}
}
What the code i need to write inside the onUpload() to assign the path of the input image to the variable imagePath.
Please help me.