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

207
Visualizações
Toggling the visibility of a component with an Input function in Angular

I have a component that accepts a callback function @Input() closeCallback: () => void;

and calls it in a close function like this :

  close() {
    this.closeCallback();
  }
<button class="close" (click)="close()">
        <img src="assets/img/share/icon_close_dark.svg" />
    </button>

So in the parent component I passed a function to it :

<ng-container  *ngIf="isPopupOpen">
<e2-fullscreen-popup
  [title]="'top promotions'"
  [closeCallback]="closePopup"
  >
...
</e2-fullscreen-popup>
</ng-container>
  closePopup() {
   
    this.isPopupOpen = false;
    console.log('this.isPopupOpen',this.isPopupOpen);
  }

so why I'm not able to remove the component when clicking on the button, even thou the logs themselves show that this.isPopupOpen is false?

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

0

@Input is used to pass data to the child component; to implement a callback you need to use @Output.

In your child component:

@Output() closeCallback = new EventEmitter();

// ...

close() {
  this.closeCallback.emit();
}

In your parent component:

<ng-container  *ngIf="isPopupOpen">
<e2-fullscreen-popup
  [title]="'top promotions'"
  (closeCallback)="closePopup($event)"
  >
...
</e2-fullscreen-popup>
</ng-container>
closePopup(dataFromChild: any){
  // handle callback
  this.isPopupOpen = false;
  console.log('this.isPopupOpen',this.isPopupOpen);
}

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