【问题标题】:Angular 4 - Supplied parameters do not match any signature of call targetAngular 4 - 提供的参数与调用目标的任何签名都不匹配
【发布时间】:2017-10-26 00:20:26
【问题描述】:

我收到以下错误。 addControl 具有以下签名。不知道我做错了什么。

(method) FormGroup.addControl(name: string, control: AbstractControl): void  

【问题讨论】:

    标签: angular angular-components angular-reactive-forms


    【解决方案1】:

    FormBuilder.control 方法具有以下签名

    control(formState: Object, validator?: ValidatorFn | ValidatorFn[] | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl;
    

    所以它需要初始值。你必须通过formStatelike

    this.fb.control('')
    

    this.fb.control(null)
    

    这是您的代码的外观

    createGroup() {
      const group = this.fb.group({});
      this.config.forEach(control => group.addControl(control.name, this.fb.control('')));
      return group;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 2016-11-14
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多