Получение ошибки при динамическом задании значения в Angular реактивном управлении формой - PullRequest
0 голосов
/ 15 января 2020

Я получаю ошибку ниже, когда устанавливаю значение в Dynami c Управление реактивной формой с использованием Angular.

ERROR TypeError: Cannot read property 'setValue' of undefined

Я объясняю мой код ниже.

createForm(){
    try{
    this.customerForm = this.fb.group({
      CustomerFirstName: ['', Validators.required],
        CustomerLastName: [''],
        CustomerMobile: ['', [Validators.required, Validators.pattern('[6-9]\\d{9}') ]],
        CustomerAlternateMobile: ['',Validators.pattern('[6-9]\\d{9}')],
        CustomerType: [false, Validators.required],
        CustomerEmail: ['',Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$')],
        CustomerPrefix: [''],
        CustomerImage: [],
        IsActive: [false, Validators.required],
        IsShippingAddressSameAsBillingAddress: [false],
        CustomerFullName: [''],
      BillingAddresses: this.fb.group({
        BillingFirstName: [''],
        BillingLastName: [''],
        BillingEmail: [''],
        BillingMobile: [''],
        BillingAddressLine1: [''],
        BillingAddressLine2: [''],
        BillingStreet: [''],
        BillingCity: [''],
        BillingState: [''],
        BillingCountry: [''],
        BillingPinCode: [''],
        BillingLatitude: [''],
        BillingLongitude: [''],
        BillingGSTN: [''],
        BillingGSTStateCode: [''],
        BillingIsAvailable: [false],
        BillingIsDefault:[false]
      }),
      ShippingAddresses: this.fb.group({
        ShippingFirstName: [''],
        ShippingLastName: [''],
        ShippingEmail: [''],
        ShippingMobile: [''],
        ShippingAddressLine1: [''],
        ShippingAddressLine2: [''],
        ShippingStreet: [''],
        ShippingCity: [''],
        ShippingState: [''],
        ShippingCountry: [''],
        ShippingPinCode: [''],
        ShippingLatitude: [''],
        ShippingLongitude: [''],
        ShippingGSTN: [''],
        ShippingGSTStateCode: [''],
        ShippingIsAvailable: [false],
        ShippingIsDefault:[false]
      })
  });
  }catch(err)
  {
    console.log('anilerror', err.message);
  }

  }

sameAsBillingEvent (event : any) {
    if (event.checked) {
      this.customerForm.controls['IsShippingAddressSameAsBillingAddress'].setValue(event.checked);
      this.customerForm.get('ShippingAddresses').get['ShippingFirstName'].setValue(this.customerForm.controls['BillingFirstName'].value);

    }else {

     this.customerForm.controls['IsShippingAddressSameAsBillingAddress'].setValue(event.checked);
    }
  }

Здесь я пытаюсь скопировать значение адреса выставления счета в адрес доставки, но оно выдает вышеуказанную ошибку. Мне нужно, когда пользователь нажмет на кнопку same as, все значения платежного адреса будут скопированы на адрес доставки.

...