Reputation: 13
I am using Angular8 and I need to show the message in HTML but only on the first visit on this page. And after when I back on this page this message is hidden. How to make it?
Upvotes: 1
Views: 1370
Reputation: 18973
You can use localStorage as
constructor(){
this.firsttime = localStorage.getItem('firsttime');
if(localStorage.getItem('firsttime') == null || localStorage.getItem('firsttime') == undefined) {
this.firsttime = 'true';
localStorage.setItem('firsttime', 'true');
}
else localStorage.setItem('firsttime', 'false');
}
Demo code: https://stackblitz.com/edit/angular-firsttime1
Upvotes: 3
Reputation: 1
Hie Helen , You can show that message using your cookie service or local-storage or via database , you can check using condition if the cookie for that particular is saved or not , if not you can show the message or if the cookie is saved you can make it hidden
Upvotes: 0