How to add localstorage in Typescript (Angular 6)

0

I have code in Typescript (angular 6) in which I for educational reasons, I want to know how to save several message variables with the following data in the cache:

adicionarMensagem(preparacao: PreparacaoDeMensagem) {
    let mensagem = {
        texto: preparacao.texto,
        data: preparacao.data,
        contato: preparacao.contato,
        souEumesmo: preparacao.contato === this.emissor,
}

This is the function I use to add a message, but I also want to save it in the browser cache.

    
asked by anonymous 28.09.2018 / 21:00

1 answer

0

In brower, among other storage modes there is the localstorage that can be accessed via window.localstorage

For example within the function that showed it would just call the function window.localstorage.setItem(‘menssagem’, JSON.stringify(menssagem)) that its object will be persisted.

I hope I have helped

    
08.10.2018 / 04:35