Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
ERROR TypeError: Cannot read properties of null (reading 'setItem')
private currentStorage = null;

setItem(key: string, value: string) {
    this.currentStorage.setItem(key, value);
}

When I run my code (the above snippet is the only one that contains the setItem) I get the following error:

ERROR TypeError: Cannot read properties of null (reading 'setItem')
    at SessionService.setItem (session.service.ts:53:23)
    at authentication.service.ts:58:37
    at map.js:7:1
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)
    at OperatorSubscriber.next (Subscriber.js:31:1)
    at map.js:7:1
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)
    at OperatorSubscriber.next (Subscriber.js:31:1)
    at filter.js:6:50
    at OperatorSubscriber._next (OperatorSubscriber.js:13:1)

I've tried many ways to define the currentStorage but the error is the same or sometimes says "properties of undefined" instead of "properties of null".

Can anyone explain what is happening?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this was all could provide based on question

setItem(key: string, value: string) {
        if(this.currentStorage){
        this.currentStorage.setItem(key, value);
        }
        else{
         ...
         //could do nothing here or create the storage
         this.currentStorage = ...
         this.currentStorage.setItem(key, value);
        }
    }

but if you are looking for actual change needed for session storage

    setItem(key: string, value: string) : void {
            sessionStorage.setItem(key, JSON.stringify(value));
        }
    
    /** get an item from session storage */
    getItem(string: key) : any | undefined{
 let value = sessionStorage.getItem(key);
if(value){
return JSON.parse(value);
}
return undefined;
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda