Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
¿Cómo puedo llamar al mismo método secundario cuando tengo la lista del mismo componente secundario en el componente principal en angular?

Este es padre.html

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

Este es child.compenent

 export class ChildComponent implements OnInit { @Input() index: number; @Input() detailsItem: any; constructor() { } ngOnInit() { } saveChild(){ console.log('index', this.index); } }

Y quiero llamar al método saveChild en parentComponent así:

 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 answers
Answer question

0

puede usar @ViewChild para ejecutar eso.

 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(); } }

Le permitirá acceder a las propiedades y métodos dentro de ChildComponent. Sin embargo, recuerde usar ngAfterViewInit para que el niño se inicialice cuando intente acceder a él.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!