title: Can't resolve all parameters in validation directive during ng build --prod
body: <p>I have go through with following questions but didn't found any solution. </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/45194125/angular-4-directive-error-cant-resolve-all-parameters-for-directive">Angular 4 directive error: Can&#39;t resolve all parameters for directive</a></li>
  <li><a href="https://stackoverflow.com/questions/46090874/cant-resolve-all-parameters-for-custom-directive">Can&#39;t resolve all parameters for custom directive</a></li>
  </ul>
  
  <p>I have made a custom validation directive to validate unique permalink. this code working fine but when i try to create a build for production then it gives me following error:-</p>
  
  <blockquote>
    <p>ERROR in : Can't resolve all parameters for
    UniquePermalinkValidatorDirective in
    E:/Manish/Projects/ampleAdmin/src/app/shared/permalink-validation.directive.ts:
    ([object Object], ?).</p>
  </blockquote>
  
  <p><strong>permalink-validation.directive.ts</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>import { Directive } from '@angular/core';
  import { AsyncValidator, AbstractControl, ValidationErrors, NG_ASYNC_VALIDATORS, AsyncValidatorFn } from '@angular/forms';
  import { Observable, of } from 'rxjs';
  import { map } from 'rxjs/operators';
  import * as qs from 'qs';
  import { PageService } from '../services/page.service';
  import { IPage } from '../client-schema';
  
  export function UniquePermalinkValidator(pageService: PageService, page: IPage): AsyncValidatorFn {
    return (ctrl: AbstractControl): Promise&lt;ValidationErrors | null&gt; | Observable&lt;ValidationErrors | null&gt; =&gt; {
      if (!(ctrl &amp;&amp; ctrl.value)) { return null; }
  
      const cond: any = {
        where: {
          permalink: ctrl.value
        }
      };
  
      if (page &amp;&amp; page.id) {
        cond.where.id = { nin: [page.id]};
      }
      const query = qs.stringify(cond, { addQueryPrefix: true });
  
      return pageService.getPageCount(query).pipe(
        map(res =&gt; {
          return res &amp;&amp; res.count ? { uniquePermalink: true } : null;
        })
      );
    };
  }
  
  @Directive({
    selector: '[appUniquePermalink]',
    providers: [{ provide: NG_ASYNC_VALIDATORS, useExisting: UniquePermalinkValidatorDirective, multi: true }]
  })
  export class UniquePermalinkValidatorDirective implements AsyncValidator {
  
    constructor(private pageService: PageService, private page: IPage) { }
  
    validate(ctrl: AbstractControl): Promise&lt;ValidationErrors | null&gt; | Observable&lt;ValidationErrors | null&gt; {
      return UniquePermalinkValidator(this.pageService, this.page)(ctrl);
    }
  }
  </code></pre>
  
  <p><strong>page.component.ts</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>import { Component, OnInit, TemplateRef } from '@angular/core';
  import * as _ from 'lodash';
  import { NotifierService } from 'angular-notifier';
  import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
  import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  import { IPage } from 'src/app/client-schema';
  import { Utils } from 'src/app/shared/utils';
  import { PageService } from 'src/app/services/page.service';
  import { UniquePermalinkValidator } from 'src/app/shared/permalink-validation.directive';
  
  @Component({
    selector: 'app-page',
    templateUrl: './page.component.html',
    styleUrls: ['./page.component.css']
  })
  export class PageComponent implements OnInit {
  
    private notifier: NotifierService;
  
    pageForm: FormGroup;
    pageDetail: IPage;
  
    isAddFold = false;
    isEditFold = false;
    editFoldIndex = -1;
  
    constructor(
      private pageService: PageService,
      private notifierService: NotifierService,
      private modalService: BsModalService,
      private formBuilder: FormBuilder,
    ) {
      this.notifier = notifierService;
    }
  
    initPageForm() {
      this.pageForm = this.formBuilder.group({
        name: ['', [Validators.required, Validators.minLength(2), Validators.maxLength(250)]],
        permalink: ['', [Validators.required], UniquePermalinkValidator(this.pageService, this.pageDetail)],
        folds: [
          []
        ],
        data: null,
        status: true
      });
    }
  }
  </code></pre>
  
  <p>I am using single form for Add/Edit page so i have to require records details to allow permalink on editing a page. </p>
  
  <p>is there any way to pass current page details to directive?</p>