Please could you share a simple file upload sample that conveys the basics of such functionality when using Angular 2?
The research I did (am doing) keeps bubbling up older versions of Angular. At this point all I'm trying to do is load a small image file into a property, or local storage, and have it displayed on the webpage.
I imagine it implies the use of HttpClient however as I'm new to Angular 2 it's challenging to drum up the beginnings of how this works without leaning on a simple sample.
I'm trying this and it's not having the effect I was expecting. It feels like I'm missing an import. This portion is only trying to get the name of the file out, not the image rendered. It appears using [(ngModel)] is not an option, and I must resort to change event to get the selected file.
Component
@Component({
selector:'home-page'
,templateUrl:'./home.page.html'
})
export class HomePageComponent{
CurrentFile:File;
public FileChangeEvent(fileInput:any){
this.CurrentFile = fileInput.target.files[0];
}
}
html
<div>
<input type="file" (change)="FileChangeEvent($event)">
<div *ngIf="CurrentFile">
<p>{{CurrentFile.name}}</p>
</div>
</div>