Is it possible to include ElementRef in NgControl?

I am trying to create a special validator like @Directive, and the problem is that in the constructor I can only access ElementRef object, however I need some methods from NgControl.

@Directive({
  selector: "[my-directive][ngModel]",
  providers: [some providers here]
})
export class MyValidator extends RootValidator {


  constructor(el: ElementRef, public renderer: Renderer) {
    super(el, renderer);
    // TODO: Here i need access to ngControl instead of ElementRef
    errorsFromServerEmitter.subscribe(next => {
        // ... some useful code here and then
        ngControl.updateValueAndValidity();
    })
  }

  validate(c: FormControl) {
    // ... some validations
    return errors;
  }

I need to somehow respond to server responses. In these answers I get " extended" errors that know about DB consistency and some other things ...

+4
source share

Source: https://habr.com/ru/post/1650317/


All Articles