<!-- #docplaster -->
<!-- #docregion final -->
<div class="container">
  <!-- #docregion edit-div -->
  <div [hidden]="submitted">
    <h1>Hero Form</h1>
    <!-- #docregion ngSubmit -->
    <form (ngSubmit)="onSubmit()" #heroForm="ngForm">
      <!-- #enddocregion ngSubmit, edit-div -->
      <div class="form-group">
        <!-- #docregion name-with-error-msg -->
        <label for="name">Name</label>
        <input type="text" class="form-control" id="name"
               required
               [(ngModel)]="model.name" name="name"
               #name="ngModel">
        <!-- #docregion hidden-error-msg -->
        <div [hidden]="name.valid || name.pristine"
             class="alert alert-danger">
        <!-- #enddocregion hidden-error-msg -->
          Name is required
        </div>
        <!-- #enddocregion name-with-error-msg -->
      </div>

      <div class="form-group">
        <label for="alterEgo">Alter Ego</label>
        <input type="text" class="form-control" id="alterEgo"
               [(ngModel)]="model.alterEgo" name="alterEgo">
      </div>

      <div class="form-group">
        <label for="power">Hero Power</label>
        <select class="form-control" id="power"
                required
                [(ngModel)]="model.power" name="power"
                #power="ngModel">
          <option *ngFor="let pow of powers" [value]="pow">{{pow}}</option>
        </select>
        <div [hidden]="power.valid || power.pristine" class="alert alert-danger">
          Power is required
        </div>
      </div>

      <!-- #docregion submit-button -->
      <button type="submit" class="btn btn-success" [disabled]="!heroForm.form.valid">Submit</button>
      <!-- #enddocregion submit-button -->
      <!-- #docregion new-hero-button-form-reset -->
      <button type="button" class="btn btn-default" (click)="newHero(); heroForm.reset()">New Hero</button>
      <!-- #enddocregion new-hero-button-form-reset -->
 <!-- #enddocregion final -->
      <i>with</i> reset

      &nbsp;&nbsp;
      <!-- #docregion new-hero-button-no-reset -->
      <button type="button" class="btn btn-default" (click)="newHero()">New Hero</button>
      <!-- #enddocregion new-hero-button-no-reset -->
      <i>without</i> reset

     <!-- NOT SHOWN IN DOCS -->
      <div>
        <hr>
        Name via form.controls = {{showFormControls(heroForm)}}
      </div>
     <!-- - -->
<!-- #docregion final -->
    </form>
  </div>

  <!-- #docregion submitted -->
  <div [hidden]="!submitted">
    <h2>You submitted the following:</h2>
    <div class="row">
      <div class="col-xs-3">Name</div>
      <div class="col-xs-9">{{ model.name }}</div>
    </div>
    <div class="row">
      <div class="col-xs-3">Alter Ego</div>
      <div class="col-xs-9">{{ model.alterEgo }}</div>
    </div>
    <div class="row">
      <div class="col-xs-3">Power</div>
      <div class="col-xs-9">{{ model.power }}</div>
    </div>
    <br>
    <button class="btn btn-primary" (click)="submitted=false">Edit</button>
  </div>
  <!-- #enddocregion submitted -->
</div>
 <!-- #enddocregion final -->

<!-- ====================================================  -->
  <div>
    <form>
<!-- #docregion edit-div -->

       <!-- ... all of the form ... -->

    </form>
  </div>
<!-- #enddocregion edit-div -->

<!-- ====================================================  -->
<hr>
<style>
  .no-style .ng-valid {
  border-left: 1px  solid #CCC
}

  .no-style .ng-invalid {
  border-left: 1px  solid #CCC
}
</style>
<div class="no-style" style="margin-left: 4px">
  <div class="container">
      <h1>Hero Form</h1>
      <form>
        <div class="form-group">
          <label for="name">Name</label>
          <input type="text" class="form-control" id="name" required>
        </div>

        <div class="form-group">
          <label for="alterEgo">Alter Ego</label>
          <input type="text" class="form-control" id="alterEgo">
        </div>

        <!-- #docregion powers -->
        <div class="form-group">
          <label for="power">Hero Power</label>
          <select class="form-control" id="power" required>
            <option *ngFor="let pow of powers" [value]="pow">{{pow}}</option>
          </select>
        </div>

        <!-- #enddocregion powers -->
        <button type="submit" class="btn btn-success">Submit</button>

      </form>
  </div>

  <!-- ====================================================  -->
  <hr>
  <div class="container">
      <h1>Hero Form</h1>
      <!-- #docregion template-variable-->
      <form #heroForm="ngForm">
      <!-- #enddocregion template-variable-->
    <!-- #docregion ngModel-2-->
        {{diagnostic}}
        <div class="form-group">
          <label for="name">Name</label>
          <input type="text" class="form-control" id="name"
                 required
                 [(ngModel)]="model.name" name="name">
        </div>

        <div class="form-group">
          <label for="alterEgo">Alter Ego</label>
          <input type="text"  class="form-control" id="alterEgo"
                 [(ngModel)]="model.alterEgo" name="alterEgo">
        </div>

        <div class="form-group">
          <label for="power">Hero Power</label>
          <select class="form-control"  id="power"
                  required
                  [(ngModel)]="model.power" name="power">
            <option *ngFor="let pow of powers" [value]="pow">{{pow}}</option>
          </select>
        </div>

    <!-- #enddocregion ngModel-2-->
        <button type="submit" class="btn btn-success">Submit</button>

      </form>
  </div>

  <!-- EXTRA MATERIAL FOR DOCUMENTATION -->
  <hr>
  <!-- #docregion ngModelName-1 -->
    <input type="text" class="form-control" id="name"
           required
           [(ngModel)]="model.name" name="name">
    TODO: remove this: {{model.name}}
  <!-- #enddocregion ngModelName-1 -->
  <hr>
    <input type="text" class="form-control" id="name"
           required
           [ngModel]="model.name" name="name"
           (ngModelChange)="model.name = $event">
    TODO: remove this: {{model.name}}
</div>
