samedi 30 mars 2019

How to set Angular header value in localstorage?

saveStudentDetails(values) {
  const studentData = {};

  studentData['id'] =  values.id;
  studentData['password'] =  values.password;

  this.crudService.loginstudent(studentData).subscribe(result => {
    // Here should be the value of the header from backend to be store on localstorage
    this.toastr.success('You are logged in', 'Success !', { positionClass: 'toast-bottom-right' });
    this.router.navigate(['/address']);
  },
    err => {
      console.log('status code ->' + err.status);
      this.toastr.error('Please try again', 'Error !', { positionClass: 'toast-bottom-right' });
 });

I have a JWT token that has been sent from backend when the user logged in into the system, how can i set the token from the header into localstorage? Thank you very much.




Aucun commentaire:

Enregistrer un commentaire