我需要传递url参数以将后端一起形成参数。我从URL这样获得令牌参数:
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]
});
}
在我的onSubmit
方法上,我有它:
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();
});
}
updatePassword
方法
public updatePassword(password: string, password_confirmation: string, reminder: string): Observable<any> {
return this.httpClient.post(url, {
password, password_confirmation, reminder
});
}
我需要传递这样的参数:
public updatePassword(password: string, password_confirmation: string, reminder: string, token: string): Observable<any> {
return this.httpClient.post(url, {
password, password_confirmation, reminder, token
});
}
如何将token
,password
和password_confirmation
参数一起包含在reminder
中?
答案 0 :(得分:1)
您总是可以像这样从路由快照获取queryParams
const total = 100;
let otherNumbers = [100, 200];
const otherNumbersMatches = otherNumbers.find(num => num === total);
if ((total >= 52001 && total <= 52006) || otherNumbersMatches) {
// do something
console.log('Matches')
}
并将其作为请求正文
传递