Save return service variable in Angular

Asked

Viewed 428 times

0

I have a service that returns me a user object with a user id:

My object:

export class Usuario{
    email: string;
    password: string;
}

In my component I urge my object to get the return of service:

usuario: Usuario = new Usuario();

And then my service does the request by returning the object with the id I need:

 this.authService.fazerLogin(email,password)
     .subscribe(
          (data) => {
              this.usuario = data;
          )}

If I do a console.log(user), I get the id I need, but I would like to save the return in a string variable instead of an object so that in the future I save this value in a localstorage to make requests...

How I extract this value for a variable?

1 answer

0


You can do it like this:

let suaVariavel = JSON.stringify(data);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.