Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda