Angular4 - No value accessor for form control

no value accessor for form control with name unit test jasmine
no value accessor for form control with name angular 8
error: no value accessor for form control with name angular 7
no value accessor for form control with name mat-select
no value accessor for form control with name angular 9
no value accessor for form control with name radio-button
no value accessor for form control with name mat-checkbox
no value accessor for form control with name primeng

I have a custom element :

<div formControlName="surveyType">
  <div *ngFor="let type of surveyTypes"
       (click)="onSelectType(type)"
       [class.selected]="type === selectedType">
    <md-icon>{{ type.icon }}</md-icon>
    <span>{{ type.description }}</span>
  </div>
</div>

When I try to add the formControlName, I get an error message:

ERROR Error: No value accessor for form control with name: 'surveyType'

I tried to add ngDefaultControl without success. It seems it's because there is no input/select... and I dont know what to do.

I would like to bind my click to this formControl in order that when someone clicks on the entire card that would push my 'type' into the formControl. Is it possible?

No value accessor for form control, 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"� Angular Error: "No value accessor for form control with unspecified name attribute" on div. "No value accessor for form control with unspecified name attribute

I think you should use formControlName="surveyType" on an input and not on a div

No value accessor for from control � Issue #1018 � angular , What is the current behavior? main.987e5bf….bundle.js:17 EXCEPTION: No value accessor for form control with name: 'username' What ar No value accessor for form control with name: 'email' I also tried to add ngDefaultControl to the custom input component because of this my input disappears. CustomEmailComponent.html

No value accessor for form control with name 'control-name' : Angular2, I'm trying to learn how to design a custom form control in Angular 5, by following one of the many tutorials I found. However, at the end of every … Your providers array are in the wrong place: it's the int-phone-prefix that should have the NG_VALUE_ACCESSOR, not the testing module itself. The simplest solution would be to stub the three required ControlValueAccessor methods for the stub IntPhonePrefixComponent (and move the provide: NG_VALUE_ACCESSOR // etc. fragment to its decorator).

For me it was due to "multiple" attribute on select input control as Angular has different ValueAccessor for this type of control.

const countryControl = new FormControl();

And inside template use like this

    <select multiple name="countries" [formControl]="countryControl">
      <option *ngFor="let country of countries" [ngValue]="country">
       {{ country.name }}
      </option>
    </select>

More details ref Official Docs

How to write custom form controls in Angular, “No value accessor for form control with the name: “cash”, even harder, than the previous one. as we fill find out, there is nothing difficult there,� There should be an value accessor. What is the current behavior? main.987e5bf….bundle.js:17 EXCEPTION: No value accessor for form control with name: 'username' What are the steps to reproduce? This bug occurs only if you run ng build --prod. Use angular-cli@webpack to create a new project.

No value accessor for form control with name - angular - html, I am using mat-list in a with a reactive forms. I've given formControlName to the mat-list, but I am getting the following error: No value accessor for form control� How to use Angular's Control Value Accessor Interface to conquer all Angular form problems. July 31, 2019 If you’re dealing with forms in Angular on a regular basis, one of the most powerful things you can learn is how to use the Control Value Accessor interface.

No value accessor for form control with name error in angular 7 , But, when I wrote formControlName, then it gave me error No value accessor for form control with name: 'brand' STACKBLITZ I added this code which I saw from� Lets take a look at the built-in value accessors provided by the Angular Core. Since our form control (component) doesn’t falls in any these categories, angular compiler throws error stating no

No value accessor for form control with name for mat , I am making some unit test with jasmine and karma for an angular 6 app that validate i. Since Angular provides control value accessors for all default native controls a new value accessor is most often implemented to wrap 3rd party plugins/widgets. I mentioned a slider widget from jQueryUI library earlier and this is the plugin we will use for our custom form control.

Comments
  • I don't know my point is that : formControl go for form control in html but div is not a form control. I would like tu bind my surveyType with the type.id of my card div
  • i know i could use the old angular way and have my selectedType bind to it but i was trying to use and learn reactive form from angular 4 and dont know how to use formControl with this type of case.
  • Ok i it s maybe jsut that case can't be handle by a reactive form so. Thx anyway :)
  • I've made an answer about how to break down huge forms into sub components here stackoverflow.com/a/56375605/2398593 but this also apply very well with just a custom control value accessor. Also check out github.com/cloudnc/ngx-sub-form :)
  • Yes sure, but i dont know how to turn my card div into something else which will be a html form control
  • The point of CustomValueAccessor is to add form control to ANYTHING, even a div
  • @SoEzPz This is a bad pattern though. You mimic Input functionality in a wrapper component, re-implementing standard HTML-methods yourself (thus basically re-inventing the wheel and making your code verbose). but in 90% of the cases you can accomplish all you want by using <ng-content> in a wrapper component and let the parent component that defines formControls simply put the <input> inside the <wrapper>
  • What was due to "multiple"? I don't see how your code solves anything, or what was the original problem. Your code shows the usual basic usage.