skip to Main Content

As you can see currently i send the form data as this.loginForm.value now the thing is that I have too more properties planId and service that I want to send along with the data.
One way is that i recreate the object as below and send it but it is not convenient.

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)=>{
             ........
            })
       }

2

Answers


  1. May be you can try like this…

    let data = this.loginForm.value;
    data['planId'] = this.planId;
    data['service'] = this.service;
    this.auth.loginUser(data).subsribe((res)=>{
        ........
    })
    
    Login or Signup to reply.
  2. May be this will help

    const objData = Object.assign({'planId' : this.planId, 'service': this.service},this.loginForm.value);
    
    this.auth.loginUser(objData ).subsribe((res)=>{
        ........
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search