zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Angular2 Form] Group Inputs in Angular 2 Forms with ngModelGroup

Angular in with group Form forms Angular2
2023-09-14 08:59:19 时间

The ngModelGroup directive allows you to group together related inputs so that you structure the object represented by the form in a useful and predictable way. ngModelGroup is often used in combination with fieldset as they mostly represent the same idea of “grouping together inputs.”

 

  <form name="myForm2" #formRef2="ngForm" (ngSubmit)="onSubmit(formRef2.value)">
    <fieldset ngModelGroup="login">
      <legend>Login:</legend>

      Username: <input type="text" name="username" ngModel required>
      Password: <input type="password" name="password" ngModel requried>

    </fieldset>
  </form>
  <pre>
    form value: {{formRef2.value | json}}
    form valid: {{formRef2.valid | json}}
  </pre>

 

Github