生产版本上的Angular4编译错误:“AbstractControl类型上不存在属性控件”

问题描述 投票:2回答:2

我的代码在开发模式下构建和运行完美。当我为生产而构建时,我在此行中收到此错误:

        <div *ngFor="let child of form.controls.emailsArray.controls; let i=index">

表单构建如下:

  public form: FormGroup;
  private control: FormArray;
  private emailsModel = { emails: ['','','','','']}  // the model, ready to hold the emails
  private fb : FormBuilder;

  constructor() {}

  ngOnInit() {
    this.fb = new FormBuilder;
        this.form = this.fb.group({
      emailsArray: this.fb.array([])
    });
    this.control = <FormArray>this.form.controls['emailsArray'];
    this.patch();    
  }

  private patch(): void {
    // iterate the object model and extra values, binding them to the controls
    this.emailsModel.emails.forEach((item) => {
      this.control.push(this.patchValues(item));
    })
  }

  private patchValues(item: string): AbstractControl {
    return this.fb.group({
      email: [item, Validators.compose([emailValidator])] 
    })
  }

那么如何在html中引用这些子控件呢?

注意:类似于this question,除了我的错误发生在HTML中,而不是打字稿。

angular angular-reactive-forms
2个回答
6
投票

我不确定这是不是很好的做法,但将HTML更改为有效:

<div *ngFor="let child of form.controls.emailsArray['controls']; let i=index">

1
投票

对我来说,这解决了它:

更改

meeting.controls.schedule.controls['scheduleEnd']

meeting.controls.schedule['controls'].frequency
© www.soinside.com 2019 - 2024. All rights reserved.