I'm setting localStorage inside ngOnDestroy and retriving it in ngOnInit. It works when user navigates to other view but it's not setting the localStorage on exiting the browser.
//currentnote is my variable which is connected with 2 way binding with the input field
ngOnInit() {
let unsavedNote = localStorage.getItem('unsavedNote');
if(unsavedNote) {
this.currentnote=unsavedNote;
}
}
ngOnDestroy(){`enter code here`
if(this.currentnote && this.currentnote!=""){
localStorage.setItem('unsavedNote', this.currentnote);
}
}