angular-数据持久化

storage.service.ts文件

import {
      Injectable } from '@angular/core';

@Injectable({
     
  providedIn: 'root'
})
export class StorageService {
     

  constructor() {
      }

  set(key:string,value:any){
     
    localStorage.setItem(key,JSON.stringify(value));
  }


  get(key:string){
     
    return JSON.parse(localStorage.getItem(key))
  }

  remove(key:string){
     
    localStorage.removeItem(key);
  }

}



你可能感兴趣的:(angular)