嵌套形式的角度2

时间:2017-05-18 11:49:36

标签: angular angular2-template angular2-forms

我正在使用嵌套的角形式。我正在使用数组。但是在此使用两个动态组件时,我们点击多次时添加。但问题是当我们添加第一个项目时,第二个项目会自动添加到表单中。我正在使用两个组件 titleXIX ItemCCp 这两个组件完全不同但是共享array.when addNewCCpForm titleXIX表格也被添加。如何解决问题

getFormBuilder() {
    this.orderForm = this.fb.group({
      orderType: 1,
      entity: 3,
      refusalReason: '',
      coordinator: this.fb.group({
        id: ['', Validators.required]
      }),
      patient: this.fb.group({
        id: ['', Validators.required]
      }),
      hsp: this.fb.group({
        id: ['', Validators.required]
      }),
      vendor: this.fb.group({
        id: ['', Validators.required]
      }),
      vendorContact: this.fb.group({
        // TODO : right now hardcoded as order creation failing if vendor-contact empty.
        id: '4'
      }),
      providerGroup: this.fb.group({
        id:11
      }),
      shippingAddress: this.fb.group({
        city: '',
        line1: '',
        line2: '',
        state: '',
        zip: ''
      }),
      customDetails: this.fb.group({
        ccpForm: true,
        titleXIXForm: false,
        extraInformation: '',
        ccpIcd9: ['', Validators.required],
        estimatedDeliveryDate: '',
        ccpDateOfServiceFrom: ['', Validators.required],
        ccpDateOfServiceTo: ['', Validators.required],
        ccpDiagAndMedNecessityOfServices: '',
        lines: this.fb.array([
          this.CPPItem()
        ]),
        initial: this.fb.group({
          from: '',
          to: '',
          checked: false
        }),
        recertification: this.fb.group({
          from: '',
          to: '',
          checked: false
        }),
        revision: this.fb.group({
          from: '',
          to: '',
          checked: false
        }),
        ccpJustification: '',
        ccpRevision: '',
        durationNeed: '',
        durationSupply: '',
        lastSeenPhysician:['',Validators.required]
      }),
    });
  }

  addNewCCPItem() {
    const control = <FormArray>this.orderForm.controls['customDetails'].get('lines');
    control.push(this.CPPItem());
  }

  removeCCPItem(i: number) {
    const control = <FormArray>this.orderForm.controls['customDetails'].get('lines');
    control.removeAt(i);
  }

  addItemXIX() {
    const control = <FormArray>this.orderForm.controls['customDetails'].get('lines');
    control.push(this.CPPItem());
  }

  removeItemXIX(i: number) {
    const control = <FormArray>this.orderForm.controls['customDetails'].get('lines');
    control.removeAt(i);
  }

  CPPItem() {
    return this.fb.group({
      additionalDocuments:this.fb.array([]),
      hcpcs:'',
      quantityFrequence:'',
      beyondQtyLimit: true,
      customItem : false,
      icd9:['',Validators.required],
      justification:'',
      price:'',
      priorAuthRequired: false,
    });
  }

0 个答案:

没有答案