如您所见,当前我以this.loginForm.value
的形式发送表单数据,现在的问题是我要与数据一起发送的属性planId
和service
太多了。
一种方法是我按以下方式重新创建对象并将其发送,但这并不方便。
const userDetails = {
email: this.loginForm.controls.email.value,
password: this.loginForm.controls.password.value,
planId: this.planId,
service: this.service
}
...
export class LoginComponent
planId = "2";
service = "seo";
ngOnInit() {
this.loginForm = this.formBuilder.group({
email: ['', [Validators.required, Validators.email]],
password: ['', Validators.required]
})
onSubmit() {
this.auth.loginUser(this.loginForm.value).subsribe((res)=>{
........
})
}
答案 0 :(得分:1)
也许这会有所帮助
const objData = Object.assign({'planId' : this.planId, 'service': this.service},this.loginForm.value);
this.auth.loginUser(objData ).subsribe((res)=>{
........
})
答案 1 :(得分:0)
也许您可以这样尝试...
let data = this.loginForm.value;
data['planId'] = this.planId;
data['service'] = this.service;
this.auth.loginUser(data).subsribe((res)=>{
........
})