title: async validation reactive forms angular with ngrx
body: <p>I need to validate if the user exists in the state of my application. In my application I'm using ngrx and through a selector I want to validate if the user exists.</p>
  
  <p><strong>How can I do this?</strong></p>
  
  <p>I'm not able to validate this way, what am I doing wrong?</p>
  
  <pre><code>return this._formBuilder.group({
    id: ['', this._existUser()],
    dateStart: ['', Validators.required],
    dateEnd: ['', Validators.required]
  })
  
    private _existUser(): AsyncValidatorFn {
      return (control: AbstractControl): Promise&lt;{ [key: string]: any } | null&gt; | Observable&lt;{ [key: string]: any } | null&gt; =&gt; {
        const userId = control.value;
        return this._store.select(usersSelectors.getUserById, { id: userId}).pipe(
          debounceTime(500),
          take(1),
          map(value =&gt; {
            // Not entering the map...
            return !!value ? { invalid: true } : null;
          })
        )
      };
    }
  </code></pre>
  
  <p><strong>selectors.ts:</strong></p>
  
  <pre><code>export const getUserById = createSelector(
      selectEntities,
      (entities, props): any =&gt; {
          return entities[props.id];
      }
  );
  </code></pre>