Thursday, April 11, 2019

LocalStorage, SessionStorage or Native Session (Angular 7 or greater)

I share example how to integrate LocalStorage, SessionStorage or Native session storage, Native local storage.

LocalStorage: If you create  local storage value, the value exist on the browser.
SessionStorage: If you create session storage value, the value exist just current tab browser, if you open new tab the value doesn't exist.

Native session is similar concepts, but you don´t need to install anything. check in the end the blog. I recommed use native session or native local storage.

Use ngx-webstorage


1. Install on project angular.

npm install --save ngx-webstorage

2. Add app.module.ts

imports: [
NgxWebstorageModule.forRoot(),
]

3.  Import on your component

import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';

4. Add on your constructor

constructor(private localSt:LocalStorageService,
private sessionSt:SessionStorageService) {}


5. Examples

/*Set*/

this.localSt.store("keyLocal", "value");
this.sessionSt.store("keySession", "2");

/*Get*/

this.localSt.retrieve("keyLocal");
this.sessionSt.retrieve("keySession");


/*remove*/
this.localSt.clear("keyLocal");
this.sessionSt.clear("keySession");


Native session or local storage javascript


*add*
sessionStorage.setItem("YOUR_KEY", YOUR_VALUE)

*Get*
sessionStorage.getItem("YOUR_KEY")

*Remove*
sessionStorage.removeItem("YOUR_KEY")


*add*
localStorage.setItem("YOUR_KEY", YOUR_VALUE)

*Get*
localStorage.getItem("YOUR_KEY")

*Remove*
localStorage.removeItem("YOUR_KEY")












Multiple Data Sources in Spring Boot 3 with Java 21

  In this blog post, we'll explore the configuration and setup for a Spring Boot 3 application with Java 21 that uses multiple data sour...