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

rmc*_*rry 3 angular angular-reactive-forms

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

        <div *ngFor="let child of form.controls.emailsArray.controls; let i=index">
Run Code Online (Sandbox Code Playgroud)

表单构建如下:

  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])] 
    })
  }
Run Code Online (Sandbox Code Playgroud)

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

注意:类似于这个问题,除了我的错误发生在HTML中,而不是打字稿.

rmc*_*rry 6

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

<div *ngFor="let child of form.controls.emailsArray['controls']; let i=index">
Run Code Online (Sandbox Code Playgroud)