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

154
Vistas
How can i call the same child method when i have the list of same child component in parent component in angular

This is parent.html

<child *ngFor="let detail of listContact; let i = index" 
        [detailsItem]="detail" [index]="i">
</child>

This is child.compenent

export class ChildComponent implements OnInit {
  @Input() index: number;
  @Input() detailsItem: any;
  constructor() {
  }
  ngOnInit() {

  }
  saveChild(){
console.log('index', this.index);
  }
}

And I want to call the method saveChild in parentComponent like this:

export class ParentComponent implements OnInit {
  private child: ChildComponent;
  @Input() index: number;
  @Input() detailsItem: any;
  constructor() {
  }
  ngOnInit() {
  }
  save(){
    this.child.saveChild();
  }
}

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

0

you can use @ViewChild to run that.

import { AfterViewInit, Component, ViewChild } from '@angular/core';
import { ChildComponent } from '../child/child.component';

@Component({
  selector: 'app-parent',
  templateUrl: './parent.component.html',
  styleUrls: ['./parent.component.css']
})
export class ParentComponent implements AfterViewInit {
  @ViewChild(ChildComponent) public child!:ChildComponent

  constructor() { }

  ngAfterViewInit(): void {
    this.child.childMethod();
  }

}

It's going to let you access the properties and methods inside the ChildComponent. However remember to use ngAfterViewInit so that the child is initialised when you try and access it.

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