[FIXED] PrimeNG Table filterGlobal TS2339: Property 'value' does not exist on type 'EventTarget'

Issue

All of the examples I have found for the PrimeNG p-table show the following example for filtering a table.

<input pInputText type="text" (input)="dt.filterGlobal($event.target.value, 'contains')" placeholder="Filter" />

When I use this I get a compile error.

error TS2339: Property 'value' does not exist on type 'EventTarget'.

Note: I do have strict mode turned on.

Solution

try to parse the target to an HTMLInputElement first:

<input pInputText type="text" (input)="applyFilterGlobal($event, 'contains')" placeholder="Filter" />

and in your component:

applyFilterGlobal($event, stringVal) {
  this.dt.filterGlobal(($event.target as HTMLInputElement).value, stringVal);
}

event.target is an HTMLElement, because you are in strict mode, and HTMLElement doesnt have the value property, the compile engine throws the error, changing the target to HTMLInputElement solves it

Answered By – Moshezauros

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published