Angular

Last Updated: 8/28/2023

ngModelGroup

  • For complex form with mulitple subgroups, apply ngModelGroup directive on subgroup, creates a form group object for that sub group
  • Sets sub property in value object
  • Use ngModelGroup directive when API on server expects complex nested object structure
  • Get a reference to the directive using the template variable and assign it to ngModelGroup. You can refer it anywhere in the template. Useful for validating the entire group
<div ngModelGroup="contact" #contact="ngModelGroup">
...
	<div *ngIf="!contact.valid">
	...
	</div>
</div>