title: Angular: Custom validation with parameter
body: <p>I am trying to implement a verify password validation with Angular 6 using Reactive Form but I can't get the best way to do it, below an example that works with "1234" but I would like to pass the value of the password control instead. 
  I tried with ValidatePWD(this) but doesn't work either.</p>
  
  <pre><code> //component.ts
   import { ValidatePWD } from './compare.validator';
  
   this.form = this._fb.group({
                    'user': ['', Validators.compose([Validators.required])],                       
                    'password': ['', Validators.compose([Validators.required])],
                    'verifypassword': ['', [Validators.required, ValidatePWD]],
  
   });
  
  
  //compare.validator.ts
  import { AbstractControl, FormGroup } from '@angular/forms';
  export function ValidatePWD(control: AbstractControl ) {    
    if (control.value != "1234") {
      return { validPWD: true };
    }
    return null;
  }
  
  
  &lt;div class="form-group"&gt;
        &lt;label&gt;Password: {{model.password}}&lt;/label&gt;
        &lt;input [(ngModel)]="model.password" [formControl]="password" class="form-control" type="password"&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
       &lt;label &gt;Verify Password&lt;/label&gt;
       &lt;input[(ngModel)]="model.verifypassword" [formControl]="verifypassword"  class="form-control" type="password"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/hTvoH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hTvoH.png" alt="enter image description here"></a></p>