Hi
In Angular 17 using Local Storage how to delete record when User confirms O.K in Modal Popup not using Confirm function
Thanks
Hi
In Angular 17 using Local Storage how to delete record when User confirms O.K in Modal Popup not using Confirm function
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jayraj ChhayaRank #304 · 8.2K reputationPosted May 13, 2024, 2:26 AM EDT
Hi Ramco Ramco,
To achieve this in Angular 17, you can create a custom modal component for confirmation. When the user clicks the delete button, open the modal for confirmation. Upon confirmation, delete the record from Local Storage.
// DeleteConfirmationComponent.ts import { Component, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'app-delete-confirmation', template: ` Are you sure you want to delete this record? OK ` }) export class DeleteConfirmationComponent { @Output() deleteConfirmed = new EventEmitter(); confirmDelete() { this.deleteConfirmed.emit(); } }In your parent component:
// ParentComponent.ts import { Component } from '@angular/core'; @Component({ selector: 'app-parent', template: ` Delete Record ` }) export class ParentComponent { openConfirmation() { // Open the modal here } deleteRecord() { // Delete record from Local Storage } }Jignesh KumarRank #91 · 22.9K reputationPosted May 13, 2024, 4:41 AM EDT
Hello,
Once you get your model pop-up open, in you component confirm button click method you can write below code to delete,
confirmDelete(id: number) { // Filter out the student with the your selected Id for student from your student list. this.studentList = this.studentList.filter(student => student.id !== id); // Update the Local Storage data after filter specified id localStorage.setItem("angular17Crud", JSON.stringify(this.studentList)); }Jayraj ChhayaRank #304 · 8.2K reputationPosted May 13, 2024, 6:23 AM EDT
To achieve record deletion confirmation using a Bootstrap Modal in Angular 17 without relying on the
confirmfunction, you can implement a custom confirmation dialog. Here's a basic example of how you can accomplish this:deleteRecord() { // Add your logic to delete the record from Local Storage here // For example, if your records are stored in an array named 'records': // this.records = this.records.filter(record => record.id !== recordIdToDelete); }By following these steps, you can implement a custom delete confirmation using a Bootstrap Modal in Angular 17 without using the standard
confirmfunction.Ramco RamcoRank #462 · 5.4K reputationPosted May 13, 2024, 2:41 AM EDT
Hi Jayraj
I want delete confirmation using BootStrap Modal
Thanks