No value accessor for form control

前端 未结 7 1997
不思量自难忘°
不思量自难忘° 2020-12-29 18:04

I\'m using Angular2-rc5, and I\'m currently getting an error on my login page. I\'m trying to make a form but the console throws exceptions telling me that it can\'t find my

相关标签:
7条回答
  • 2020-12-29 18:22

    If you must use the label for the formControl. Like the Ant Design Checkbox. It may throw this error while running tests. You can use ngDefaultControl

    <label nz-checkbox formControlName="isEnabled" ngDefaultControl>
        Hello
    </label>
    
    <nz-switch nzSize="small" formControlName="mandatory" ngDefaultControl></nz-switch>
    
    0 讨论(0)
  • 2020-12-29 18:28

    For anyone experiencing this in angular 9+

    This issue can also be experienced if you do not declare or import the component that declares your component.

    Lets consider a situation where you intend to use ng-select but you forget to import it Angular will throw the error 'No value accessor...'

    I have reproduced this error in the Below stackblitz demo.

    0 讨论(0)
  • 2020-12-29 18:37

    If you get this issue, then either

    • the formControlName is not located on the value accessor element.
    • or you're not importing the module for that element.
    0 讨论(0)
  • 2020-12-29 18:38

    You can see formControlName in label , removing this solved my problem

    0 讨论(0)
  • 2020-12-29 18:42

    You are adding the formControlName to the label and not the input.

    You have this:

    <div >
      <div class="input-field col s12">
        <input id="email" type="email"> 
        <label class="center-align" for="email" formControlName="email">Email</label>
      </div>
    </div>
    

    Try using this:

    <div >
      <div class="input-field col s12">
        <input id="email" type="email" formControlName="email"> 
        <label class="center-align" for="email">Email</label>
      </div>
    </div>
    

    Update the other input fields as well.

    0 讨论(0)
  • 2020-12-29 18:42

    In my case, I used Angular forms with contenteditable elements like div and had similar problems before.

    I wrote ng-contenteditable module to resolve this problem.

    0 讨论(0)
提交回复
热议问题