title: Validate password and confirm password Ng2
body: <p>Here are my codes:</p>
  
  <pre><code>&lt;form [formGroup]="registerForm" novalidate (ngSubmit)="doRegister()"&gt;
              &lt;div 
                  class="form-group" 
                  [ngClass]="{'has-danger': registerForm.controls.email.invalid 
                      &amp;&amp; !registerForm.controls.email.pristine}"&gt;
                  &lt;label&gt;Email&lt;/label&gt;
                  &lt;input
                    formControlName="email"
                    name="email"
                    [ngClass]="{'form-control-danger': registerForm.controls.email.invalid 
                      &amp;&amp; !registerForm.controls.email.pristine}"
                    class="form-control"
                    type="email" /&gt;
              &lt;/div&gt;
              &lt;div 
                  class="form-group"
                  [ngClass]="{'has-danger': registerForm.controls.password.invalid 
                      &amp;&amp; !registerForm.controls.password.pristine}"&gt;
                  &lt;label&gt;Password&lt;/label&gt;
                  &lt;input
                    class="form-control"
                    type="password"
                    formControlName="password"
                    name="password"
                    [ngClass]="{'form-control-danger': registerForm.controls.password.invalid 
                      &amp;&amp; !registerForm.controls.password.pristine}" &gt;
              &lt;/div&gt;
              &lt;div 
                  class="form-group"
                  [ngClass]="{'has-danger': registerForm.controls.passwordConfirm.invalid}" &gt;
                  &lt;label&gt;Password Confirm&lt;/label&gt;
                  &lt;input
                    [ngClass]="{'form-control-danger': registerForm.controls.passwordConfirm.invalid}"
                    class="form-control"
                    type="password"
                    formControlName="passwordConfirm"
                    name="passwordConfirm" &gt;
              &lt;/div&gt;
              &lt;button [disabled]="!registerForm.valid" class="btn btn-primary" type="submit"&gt;Register&lt;/button&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>And the form init part:</p>
  
  <pre><code>this.registerForm = this.formbuilder.group({
          email: ['', Validators.compose([Validators.required, validateEmail])],
          password: ['', Validators.compose([Validators.required, Validators.minLength(5)])],
          passwordConfirm: ['', ]
      })
  </code></pre>
  
  <p>Now I want to validate the password and passwordConfirm field but I don't know how, I tried to created a directive but I can't pass the formcontrol directly into it. Thank you.</p>
  
  <p>Edit:</p>
  
  <pre><code>&lt;div
                  class="form-group"
                  [ngClass]="{'has-danger': registerForm.controls.password.invalid
                      &amp;&amp; !registerForm.controls.password.pristine}"&gt;
                  &lt;label&gt;Password&lt;/label&gt;
                  &lt;input
                    formControlName="password"
                    name="password"
                    class="form-control"
                    [ngClass]="{'form-control-danger': registerForm.controls.password.invalid
                      &amp;&amp; !registerForm.controls.password.pristine}"
                    type="password"
                    validateEqual="registerForm.controls.passwordConfirm"
                    reverse="true" &gt;
              &lt;/div&gt;
              &lt;div
                  class="form-group"
                  [ngClass]="{'has-danger': registerForm.controls.passwordConfirm.invalid}" &gt;
                  &lt;label&gt;Password Confirm&lt;/label&gt;
                  &lt;input
                    formControlName="passwordConfirm"
                    name="passwordConfirm"
                    [ngClass]="{'form-control-danger': registerForm.controls.passwordConfirm.invalid}"
                    class="form-control"
                    type="password"
                    validateEqual="registerForm.controls.password" &gt;
              &lt;/div&gt;
  </code></pre>
  
  <p>It just simply doesn't work, no error.</p>