Hi
How to delete particulat student id from Local Storage Data.
Code
# -->
ID
Name
MobileNo
Action
@for (item of studentList;track $index){
-->
{{l + 1}} -->
{{item.id}}
{{item.name}}
{{item.mobileno}}
Edit
Delete -->
Edit
Delete
}JavaScript
export class AppComponent implements OnInit{
title = 'AngularFrm';
isEditMode: boolean = false;
isSubmitMode: boolean = true;
@ViewChild('myModal') model : ElementRef | undefined;
studentObj: Student = new Student();
studentList:Student[] = [];
ngOnInit(): void {
const localData = localStorage.getItem("angular17Crud");
if(localData != null){
this.studentList=JSON.parse(localData)
}
}
-------------------------------------------------
export class Student {
id:number;
name:string;
mobileno:string;
email:string;
city:string;
state:string;
pincode:string;
address:string;
constructor(){
this.id=0;
this.address ='';
this.name='';
this.mobileno='';
this.email='';
this.city='';
this.state='';
this.pincode='';
}
}Thanks

Naimish MakwanaRank #324 · 7.7K reputationPosted May 9, 2024, 4:38 AM EDT
To delete a particular student ID from the Local Storage data, you can add a
onDeletemethod in yourAppComponentclass. This method will filter out the student with the given ID from thestudentListarray and then update the Local Storage data. Here’s how you can do it:onDelete(id: number) { // Filter out the student with the given ID this.studentList = this.studentList.filter(student => student.id !== id); // Update the Local Storage data localStorage.setItem("angular17Crud", JSON.stringify(this.studentList)); }In the above code,
onDeletemethod takes a student ID as a parameter. It filters out the student with the given ID from thestudentListarray. Then, it updates the Local Storage data with the newstudentListarray.Thanks
Jobin SRank #886 · 2.4K reputationPosted May 9, 2024, 4:37 AM EDT
Hi Ramco
1.if you delete exact row in I'd to pass local storage list to find index and slice method to remove exact data
Deletefunction(id){
Var index= list.findindex(x=>x.id==id);
Localstoagelist.splice(index,1);
Then set localstorage
}