Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

356
Vistas
How to access function from parent component when in modal component?

The refreshTable() function is in the parent component. I need to trigger it whenever I updated information in my modal and closes it.

I am using @ng-bootstrap for my modal

For may parent.component.ts

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

 constructor(
private ngbModal: NgbModal,
)

viewModal() {
    const openModal = this.ngbModal.open(ModalComponent);
    openModal .componentInstance.id = row.id;
}

refreshTable() {
    //refresh code block here
}

For my modal.component.ts

import { NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';

constructor(
private activeModal: NgbActiveModal,
)

updateParent() {
    //update data to database code here
    this.activeModal.close();
}

How to trigger refreshTable() from ModalComponent after closing the modal? Since there are changes in the data from database, data from parent is not updated accordingly when modal is closed.

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Try to change to this


const openModal = this.ngbModal.open(ModalComponent);
openModal.componentInstance.id = row.id;
openModal.dismissed.subscribe(
  _ => {
    this.refreshTable();
  }
)

in parent.component.ts

about 4 years ago · Juan Pablo Isaza Denunciar

0

Pass it from the parent component to the child component as a prop.

Use bind or an arrow function to preserve the this value.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Add an output event to your modal component

@Output() onCLose: EventEmitter<any> = new EventEmitter();

When the user clicks close just call the emit() method

this.onCLose.emit(value); //value can be whatever you want to pass to the parent

Update your viewModal method in the parent to include a subscription to the close event

viewModal() {
   const openModal = this.ngbModal.open(ModalComponent);
   openModal.componentInstance.id = row.id;
   openModal.componentInstance.onClose.subscribe(value => 
      // handle the close event
      this.refreshTable();
   })
}

You could also do it any other way communication between components can be achieved:

  • service
  • state management (ngrx, etc)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda