Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Get value from directive into component

I have a directive that is used on input fields on my form. I am trying to get the value from that directive in my TS file

Directive

@Directive({
  selector: '[appOskInput]',
})
export class OskInputDirective implements OnInit {
  private isBlurTrue: boolean = false;

  @HostListener('focus')
  private onFocus() {
    console.log("focus");
    this.isBlurTrue = false;
    this.keyboard.fireKeyboardRequested(true);
    this.subscribeToKeyboardEvents();
  }

  @HostListener("onBlur")
  private onBlur() {
    console.log("blur");
    this.isBlurTrue = true;
    this.keyboard.fireKeyboardRequested(false);
    this.unsubscribeFromKeyboardEvents();
  }
}

HTML

<cb-form [formGroup]="setupForm">
  <form-input
    appOskInput
    (inputChanged)="onInputChanged($event,'accountNumber')"
    [formStatus]="formStatus"
    [parentFormGroup]="setupForm"
    [data]="{formControlName: 'accountNumber', name: 'accountNumber'}">
  </form-input>
</cb-form>

Essentially I want to use the isBlurTrue value in my TS file. Anyone knows how I can do this?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I figured it out

I just passed an output event in the directive

@Output() blurChanged = new EventEmitter();

Then emitted the value to it

this.blurChanged.emit(this.isBlurTrue);

In my HTML

I added

(blurChanged)="onBlurChanged($event)"

And in my TS I added

onBlurChanged(ev) {
  console.log(ev)
}
about 4 years ago · Juan Pablo Isaza Relatório

0

You could also have a public function within your directive where exposes your private property, and then use it in your template html from a parent control like this:

Directive

...
private isBlurTrue: boolean = false;

getBlur(): boolean {
  return this.isBlurTrue;
}

HTML

<div #myDirective="appOskInput">
  ...
  <input (blur)="myDirective.getBlur()"/>
  ...
</div>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda