Angular: composite ControlValueAccessor to implement nested form

后端 未结 2 1147
粉色の甜心
粉色の甜心 2020-11-28 14:21

Composition of ControlValueAccessor to implement nested form is introduced in an Angular Connect 2017 presentation.

https://docs.google.com/presentation/d/e/2PACX-1v

2条回答
  •  野性不改
    2020-11-28 14:30

    Couple issues, on your AppComponent change your FormBuilder to:

    this.form = fb.group({
      name: 'foo bar',
      address: fb.control({ //Not using FormGroup
        city: 'baz',
        town: 'qux',
      })
    });
    

    On your AddressFormComponent you need to initialize your FormGroup like so:

    form: FormGroup = new FormGroup({
        city: new FormControl,
        town: new FormControl
    });
    

    Here's the fork of your sample: https://stackblitz.com/edit/angular-np38bi

提交回复
热议问题