Angular 2 Typescript: TypeError: this.validator is not a function

后端 未结 3 1495
野趣味
野趣味 2020-12-17 09:27

I\'m building a form with ControlGroup and I\'m loading a class object in it. However I\'m running into the error mentioned in the title half of the time. Some forms do load

3条回答
  •  有刺的猬
    2020-12-17 09:58

    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 then a form control value.

提交回复
热议问题