TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maureen Moore
NA
206
0
localStorage data disappears after the page is refreshed
Jun 30 2020 4:53 PM
I am using a ControlValueAccessor to change my div tag to a form element and I am using localStorage to set and get my data. I am having the problem that my product_name item isn't being saved and after I refresh the page, the product_name disappears. How can I change my code so that the data persists after a page refresh?
In the HTML template:
<
div
class
=
"product_name"
name
=
"p_name"
>
</
div
>
<
div
name
=
"product_name"
(click)="add('Bike')"
style
=
"cursor:pointer;"
>
Bike
</
div
>
In the controller:
add(product_name){
localStorage.setItem(
"product_name"
, product_name);
(document.querySelector(
'.product_name'
) as HTMLElement).innerText = localStorage.getItem(
"product_name"
);
}
Reply
Answers (
2
)
formatting in excel header back color and image Logo
How to download a video from Amazon s3 browser stored in server temp f