ERROR Error: No value accessor for form control with unspecified name attribute on switch

后端 未结 20 2406
感情败类
感情败类 2020-12-07 15:33

Here is my component in Angular 4:

@Component( {
    selector: \'input-extra-field\',
    template: `
            
20条回答
  •  离开以前
    2020-12-07 16:04

    I also received this error while writing a custom form control component in Angular 7. However, none of the answers are applicable to Angular 7.

    In my case, the following needed to be add to the @Component decorator:

      providers: [
        {
          provide: NG_VALUE_ACCESSOR,
          useExisting: forwardRef(() => MyCustomComponent),  // replace name as appropriate
          multi: true
        }
      ]
    

    This is a case of "I don't know why it works, but it does." Chalk it up to poor design/implementation on the part of Angular.

提交回复
热议问题