Angular 2 Typescript: TypeError: this.validator is not a function
This happened to me when I copied/pasted from a component that implemented Validator, but failed to remove the NG_VALIDATORS provider on the new component.
Create the form in the constructor. When Angular doesn't find the form on it's first attempt to resolve bindings then it doesn't work.
this.userDetailForm
just needs to be initialized with an empty group or with a few static controls. Then when the data arrives from the server, update the group by adding/removing controls and updating values.
I had this error when I was binding an array of values in form builder the wrong way.
What I did:
fb.group({items: [1, 2, 3, 4]})
How it should be:
fb.group({items: [[1, 2, 3, 4]]})
You have to wrap everything into an array, otherwise angular thinks that [1, 2, 3, 4]
is a form control definition rather than a form control value.