I work on angular 7 project
I face issue when select file then press button upload to get selected file
then it show error Cannot read property 'files' of undefined
as below
- DeliverySystemComponent.html:25 ERROR TypeError: Cannot read property 'files' of undefined
- at Object.eval [as handleEvent] (DeliverySystemComponent.html:26)
- at handleEvent (core.js:29239)
- at callWithDebugContext (core.js:30309)
- at Object.debugHandleEvent [as handleEvent] (core.js:30036)
- at dispatchEvent (core.js:19859)
- at core.js:21044
- at SafeSubscriber.schedulerFn [as _next] (core.js:23747)
- at SafeSubscriber.__tryOrUnsub (Subscriber.js:194)
- at SafeSubscriber.next (Subscriber.js:132)
- at Subscriber._next (Subscriber.js:76)
- View_DeliverySystemComponent_0 @ DeliverySystemComponent.html:25
and that actually my issue
so How to solve this issue
what I try is
delivery html component
- <app-custom-upload #cusUpload nbTooltip="upload excel file" nbTooltipPlacement="bottom"
- nbTooltipStatus="primary" (complete)="handleFileInput($event.target.files)"></app-custom-upload>
-
- <button (click)="uploadFile(files)" class="btn btn-link" style="margin-right: 0px">
- <i nbTooltip="Import Template" nbTooltipPlacement="bottom" nbTooltipStatus="primary">
- <nb-icon icon="cloud-upload-outline"></nb-icon>
- </i>
- </button>
delivery component type script
- fileToUpload: File = null;
- handleFileInput(files: FileList) {
- if (files.length == 0) {
- return;
- }
-
- this.fileToUpload = files.item(0);
-
- }
- public uploadFile = (files) => {
-
- const formData = new FormData();
-
- formData.append('file', this.fileToUpload,this.fileToUpload.name);
- }
