I\'m creating a custom element in Angular 2.0 (
), and when I include the ngModel attribute on the component, I\'m immediately hit with the foll
I was not using new Form APIs, and I was still getting this error for NgModel
in my unit test.
Looks like just specifying NgModel
in your component isn't sufficient. e.g.
Before
directives:[NgModel]
After
directives:[FORM_DIRECTIVES]
That fixed my problem. Cheers :)
In my case it was a simple typo error. The component's selector was 'my-component' but in the html I typed <my-compoent>
. Notice last three letters? Compiles just fine and then you have this 'no value accessor' error at runtime.
From my experience you can have some other quite weird errors because of typos here and there. Typescript compiler doesn't care about markup.
I just got this error as well. And it was my stupidity. I will describe it here in case someone else jumps into it.
The format of 2 way binding for passing variables between components (let say I want to pass obj called myObj from Component A to Component B).
So inside the template for Component A I would have something like
<componentB [(myObjectInB)]="myObjectInA"></componentB>
Inside component B, I have to have an object called myObjectInB and the way we declare it must be:
@Input() myObjectInB ...
The @Input() here is what I missed so that's why it threw that error.
Try this
import {FORM_DIRECTIVES} from '@angular/forms';
Import any and all forms symbols - NgForm, Validators, etc - from @angular/forms. Importing them from @angular/common will result in a No value accessor found error.