Need to make a post request to update the current user on the home page. The expected url for the post should be in this format: "http:......./user/id". However, when the request is sent, the url becomes "http:/...../user/[object%20Object]" which causes an error. What steps can be taken to resolve this issue?
Service;
updateUser(id: number): Observable<User> {
return this.http.put<User>(`${this.url}/${id}`, id)
}
User.ts;
export interface User {
id: number
firstName: string
lastName: string
username: string
mail: string
password: string
}
home.component;
updateUser(id: number) {
this.router.navigate(['update', id]);
}
update.component;
export class UpdateUserComponent implements OnInit {
user?: User
data: any
constructor(private service: AppService, private route:
ActivatedRoute, private router: Router) { }
ngOnInit(): void {
}
form = new FormGroup({
firstName: new FormControl('', [Validators.required]),
lastName: new FormControl('', [Validators.required]),
username: new FormControl('', [Validators.required]),
mail: new FormControl('', [Validators.required]),
password: new FormControl('', [Validators.required]),
})
submit() {
this.data = this.form.value
console.log(this.data)
this.service.updateUser(this.data).subscribe(data => {
console.log(data)
})
this.router.navigate(['/']);
}
}