芯片无法在组件上的“添加表格”中工作

时间:2019-04-25 09:05:09

标签: javascript angular angular-material

所以我有两个弹出式编辑表单。一个是添加表单,一个是编辑表单。我对值“类型”的筹码实现在编辑表单上有效,但在添加表单上却无效。我不知道为什么,代码看起来一样,但没有用。有人可以帮忙吗?

add(event: MatChipInputEvent): void {
                const input = event.input;
                const value = event.value;
                console.log(`mat chip`, event);
                console.log(`mat chip value`, value);

                // Add our fruit
                if ((value || '').trim()) {

                  this.types.push(value.trim());
                  console.log(`types`, this.types);
                  this.truckDetailForm.patchValue({
                    type: this.types.join(',')
                  });
                  this.truckDetailForm.markAsDirty();
                }

                // Reset the input value
                if (input) {
                  input.value = '';
                }
              }

              remove(type: string): void {
                const index = this.types.indexOf(type);

                if (index >= 0) {
                  this.types.splice(index, 1);
                  this.truckDetailForm.patchValue({
                    type: this.types.join(',')
                  });
                  this.truckDetailForm.markAsDirty();
                }
              }


 initAddForm(): FormGroup {
    const _types = this.truck.type.split(',');
    this.types = _types.filter(t => t !== '');
    return this.formBuilder.group(
      {
        projectId: new FormControl(''),
        truckSize: new FormControl('', [Validators.required]),
        truckName: new FormControl('', [Validators.required]),
        truckBuildUp: new FormControl('', [Validators.required]),
        type: new FormControl(''),
        shiftStart: new FormControl(''),
        shiftEnd: new FormControl(''),
        maxWeight: new FormControl('', [Validators.required]),
        maxVolume: new FormControl('', [Validators.required]),
      }
    );
  }

  initEditForm(): FormGroup {
    const _types = this.truck.type.split(',');
    this.types = _types.filter(t => t !== '');
    return this.formBuilder.group(
      {
        id: new FormControl(''),
        projectId: new FormControl(''),
        truckSize: new FormControl(this.truck.truckSize, [Validators.required]),
        truckName: new FormControl(this.truck.truckName, [Validators.required]),
        truckBuildUp: new FormControl(this.truck.truckBuildUp, [Validators.required]),
        type: new FormControl(this.truck.type),
        shiftStart: new FormControl(this.truck.shiftStart, [Validators.pattern('^([0-1][0-9]|[2][0-3]):([0-5][0-9])$')]),
        shiftEnd: new FormControl(this.truck.shiftEnd, [Validators.pattern('^([0-1][0-9]|[2][0-3]):([0-5][0-9])$')]),
        maxWeight: new FormControl(this.truck.maxWeight, [Validators.required]),
        maxVolume: new FormControl(this.truck.maxVolume, [Validators.required]),
      }
    );
  }

我已经在AddForm和Editform中添加了相似的更改,但是当我键入要保存为芯片的内容时,添加表单仍然无法工作

0 个答案:

没有答案