Thursday, 22 March 2018

Angular-5 File Upload


app.component.html
<label for="file">Choose File</label>
<input type="file" id="file"(change)="Fileupload($event.target.files)">


app.component.ts

import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core';
import { Input } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit {
UploadFile: File = null;
constructor()
{

}

Fileupload(files: FileList) {
this.UploadFile = files.item(0);
}
}


output: