Angular: поместите зарегистрированный идентификатор пользователя в полезную нагрузку. - PullRequest
0 голосов
/ 23 марта 2019

как я могу получить идентификатор пользователя, который вошел в систему и поместить идентификатор пользователя в полезную нагрузку, если пользователь хочет обновить свою базу данных по своему идентификатору без того, чтобы пользователь вводил свой идентификатор вручную?

  • МОЙ КОМПОНЕНТ ЛОГИНА

    export class LoginComponent {
    
    studentForm: FormGroup;
    student: any;
    
     constructor(
      private fb: FormBuilder,
      private crudService: CrudService,
      private router: Router,
      private toastr: ToastrService) {
    
      this.studentForm = this.fb.group({
        id: ['', Validators.compose([Validators.required])],
        password: ['', Validators.compose([Validators.required])]
      });
    }
    
    saveStudentDetails(values) {
      const studentData = {};
    
      studentData['id'] =  values.id;
      studentData['password'] =  values.password;
    
      this.crudService.loginstudent(studentData).subscribe(result => {
        this.student = result;
        this.toastr.success('You are logged in', 'Success !', { positionClass: 'toast-bottom-right' });
        console.log(this.crudService.loginstudent);
        this.router.navigate(['/address']);
      },
        err => {
          console.log('status code ->' + err.status);
          this.toastr.error('Please try again', 'Error !', { positionClass: 'toast-bottom-right' });
     });
    }}
    

// МОЙ КОМПОНЕНТ РЕДАКТИРОВАНИЯ

saveStudentDetails(values) {
  // const studentData = new FormData();
  const studentData = {};

  studentData['s_pNumber'] =  values.s_pNumber;
  studentData['s_address'] =  values.s_address;
  studentData['s_pCode'] =  values.s_pCode;
  studentData['s_city'] =  values.s_city;
  studentData['s_state'] =  values.s_state;
  studentData['s_country'] =  values.s_country;

  this.crudService.createAddress(studentData).subscribe(result => {
    // this.student = result;
    this.toastr.success('Your data has been inserted', 'Success !', { positionClass: 'toast-bottom-right' });
    // this.router.navigate(['/finance']);
  },
    err => {
      console.log('status code ->' + err.status);
      this.toastr.error('Please try again', 'Error !', { positionClass: 'toast-bottom-right' });
});

}

// ЭТО МОЯ СЛУЖБА

createAddress(data) {

const postHttpOptions = {
  headers: new HttpHeaders({
    'Content-Type':  'application/json'
  })
};

postHttpOptions['observe'] = 'response';

return this.http.put(this.url + '/address/${id}', data);

}

Я не знаю, правильно ли я поступаю, кто-нибудь может мне помочь, как включить идентификатор пользователя в полезную нагрузку для отправки в бэкэнд?спасибо

1 Ответ

1 голос
/ 23 марта 2019

// Change this
return this.http.put(this.url + '/address/${id}', data);

//to this
   return this.http.put(`${this.url}/address/${id}`, data);

//use the backtick
`
// not this
'

Изображение, показывающее обратную черту

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...