Hi
How to open delete confirmation modal using viewchild
Thanks
Hi
How to open delete confirmation modal using viewchild
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted May 10, 2024, 6:30 AM
I think the ViewChild decorator doesn't find the element you're trying to query, because deleteModal.nativeElement might be undefined. Make sure you have #deleteModal defined in your HTML where you want to use ViewChild.
Then, in your component class, use ViewChild to reference the element.
Jignesh KumarPosted May 10, 2024, 6:17 AM
Ramco RamcoPosted May 10, 2024, 5:56 AM
Hi
I am getting error Object is possibly undefined.
@ViewChild('deleteModal') deleteModal: ElementRef | undefined;
onDelete(Id: number) {
const modal = this.deleteModal.nativeElement;
this.studentList = this.studentList.filter(student => student.id !== Id);
localStorage.setItem("angular17Crud", JSON.stringify(this.studentList));
}
Thanks
Jignesh KumarPosted May 10, 2024, 5:42 AM
Hello Ramco,
Please use this one,
in your ocmponent,