How to retrieve uploaded file value in ts


in html

<input type="file" [(ngModel)]="files" (change)="retriveFiles()" name="filesName" id="newsFiles" multiple accept="image/*,video/*" />

in ts how I am supposed to get not getting

     let filesName: FileList = this.nativeInputBtn.nativeElement.filesName;

cannot read property of undefined nativeElement not getting and went through lot of examples plz help


Add an $event parameter to the (change) handler. It will be an HTMLInputElement.


getting this error
Cannot read property ‘nativeElement’ of undefined

this is how I am intialising

private nativeInputBtn: ElementRef;
let filesName: FileList = this.nativeInputBtn.nativeElement.filesName;

my elementRef Code

export declare class ElementRef {
    nativeElement: any;
    constructor(nativeElement: any);


That’s lovely. Did you do what I recommended about adding an $event parameter to your change handler?


Yes bro did the same

<input type="file" [(ngModel)]="files" (change)="retriveFiles($event)" name="filesName" id="newsFiles" multiple accept="image/*,video/*" />

same as above u recommend


Then why aren’t you using the parameter in the change handler instead of bothering with all this nativeInputBtn stuff?


console.log(JSON.stringify($event)); // printing in console {“isTrusted”:true}

here I want to know how do I get file value so that I can upload that