Reputation: 83
I need to pass a url param to backend together form params. I get the token params from URL like this:
private initForm(): void {
this.route.queryParams.subscribe(params => {
const token = params['token']; // get the token from url
console.log(token)
});
this.formGroup = this.formBuilder.group({
password: ['', Validators.required],
password_confirmation: ['', Validators.required],
reminder: ['', Validators.required]
});
}
On my onSubmit
method, I have it:
public onSubmit(event: any): void {
if (this.formGroup.invalid) {
return this.formGroup.markAllAsTouched();
}
const { password, password_confirmation, reminder } = this.formGroup.value;
const subscription = this.updatePasswordComponentService
.updatePassword(password, password_confirmation, reminder)
.subscribe(result => {
console.log(result);
subscription.unsubscribe();
});
}
The updatePassword
method
public updatePassword(password: string, password_confirmation: string, reminder: string): Observable<any> {
return this.httpClient.post(url, {
password, password_confirmation, reminder
});
}
I need to pass params like that:
public updatePassword(password: string, password_confirmation: string, reminder: string, token: string): Observable<any> {
return this.httpClient.post(url, {
password, password_confirmation, reminder, token
});
}
How can I include the token
together password
, password_confirmation
and reminder
params?
Upvotes: 0
Views: 49
Reputation: 457
You always can get queryParams from route snapshot like this
this.updatePasswordComponentService.updatePassword(
password,
password_confirmation,
reminder,
this.route.snapshot.queryParams.token)
and pass it as request body
Upvotes: 1