0
My login function keeps on localstorage a token returned from the api:
localStorage.setItem('token', res.data.token);
Right after logging in, I need to pass this token to another function, but I can’t get my variable to receive the token saved on localstorage, tried something like:
ngOnInit() {
let token = localStorage.getItem('token')
this.trocaToken(token);
}
But I do get:
Cannot read Property 'token' of Undefined
If I give a console.log(localStorage.getItem('token'), it normally prints my token, but I can’t get it into a variable.