NativeElement Undefined

1,177 views
Skip to first unread message

Adnan Salahuddin

unread,
Oct 10, 2017, 12:52:49 AM10/10/17
to Angular and AngularJS discussion
Hi,

<input pInputText #fileInputCarAccident type="file" accept=".docx,image/*"  />

@ViewChild('fileInputCarAccident') fileInputCarAccident: ElementRef;

let fica: HTMLInputElement = this.fileInputCarAccident.nativeElement;

After submit button, I am getting error message and it says:
Cannot read property 'nativeElement' of undefined

If Input file is empty.

how to fix it?
I am waiting for your response.
Thanks in Advance
Message has been deleted

Sander Elias

unread,
Oct 10, 2017, 5:44:24 AM10/10/17
to Angular and AngularJS discussion

Hi Adnan,

I’m missing some context here, So I’m guessing here that your fileInputCarAccident is inside a structural directive (*ngIf, *ngFor). That means it is not visible to the component when it’s getting initialized.
Is that the case?

Regards
Sander

Reply all
Reply to author
Forward
0 new messages