I have a primeNg table in angular 13 , and when I run the command this.dt.reset()
it gives me this error , and also checking the table import and everything ok what could be ?
@ViewChild("dt", { static: false }) public dt: Table;
updateItem(itemUpdated: Item, tableName: string) {
const url = this.accountService.REST_API_SERVER_CALC + tableName + 's/' + itemUpdated.idForeign;
// console.log('VehicleService - updateItem url=' + url);
this.http.put<{ item: Item }>(url, itemUpdated)
.subscribe(responseData => {
if (responseData['Result'] === 'OK') {
const helpItem = responseData['Item'];
console.log('this.helpItem: ');
console.log(helpItem);
const itemIndex = this.items.findIndex(item => item.idItem === helpItem);
this.items[itemIndex] = helpItem;
this.selectedEditMode = undefined;
this.items = [...this.items,helpItem];
this.setItems(this.items);
this.dt.reset()// problem is in this line
this.toastr.success('Item updated');
console.log(' helpitem : '+ helpItem.name)
}
},
error => {
this.toastr.error(error.message);
console.log('ERROR:');
console.log(error);
this.error.next(error.message);
});
}
ERROR TypeError: Cannot read properties of undefined (reading 'reset') at SafeSubscriber._next (vehicle.service.ts:624:21) at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:1) at SafeSubscriber.next (Subscriber.js:122:1) at Subscriber._next (Subscriber.js:72:1) at Subscriber.next (Subscriber.js:49:1) at MapSubscriber._next (map.js:35:1) at MapSubscriber.next (Subscriber.js:49:1) at FilterSubscriber._next (filter.js:33:1) at FilterSubscriber.next (Subscriber.js:49:1) at MergeMapSubscriber.notifyNext (mergeMap.js:70:1)
I would like my table once changed the items reloaded its content
dt
seems to be undefined.
Do you call this method on ngOnInit
or via the constructor? Then maybe the initialization is too late.
What you can do to solve this is one of these two options:
dt.reset();
to dt?.reset();
updateItem
is only called when dt
is initializedNote that dt?.reset();
has a questionmark which checks if dt
is undefined
or null
and doesn't execute reset()
in that case.