How to use formControlName and deal with nested formGroup?

后端 未结 3 778
囚心锁ツ
囚心锁ツ 2020-12-07 20:12

As Angular documentation says we can use formControlName in our forms:

Hero Detail

FormControl in a Form

3条回答
  •  抹茶落季
    2020-12-07 20:40

    you can use Form group which is basically a collection of controls ( controls mean the fields given in your html form) define in your typescript syntax and binded to your HTML elements using the formControlName directive ,for example

    this.myForm = fb.group({
        'fullname': ['', Validators.required],
        'gender': [],
        'address': fb.group({
            'street': [''],
            'houseNumber': [''],
            'postalCode': ['']
        })
    });
    

    Template:

    A formGroup can consist of a nested formGroup and hierarchy can continue on ,but in accessing the value the its fairly simple .

提交回复
热议问题