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

253
Views
Angular cómo detectar cambios de padre a hijo de la siguiente manera

El componente de muestra tiene datos sobre la matriz del objeto y tiene un componente secundario en su bucle de matriz. Muestra.componente

 export class SampleComponent implements OnInit { data = [{ value: 3 }, { value: 1 }]; constructor() {} ngOnInit(): void {} valueChange() { this.data[1].value = 5; this.data = [...this.data]; } whenComponentRerendered() { console.log('Parent component rerendered'); } consoleOutput() { console.log('Console from button click'); } }
 <button (click)="valueChange()"> Change input to 5 </button> <ng-container *ngFor="let item of data"> <app-samplechild [data]="item"></app-samplechild> </ng-container>

ahora necesito detectar cambios cuando cualquier valor en el objeto cambia desde el padre

 export class SamplechildComponent implements OnInit { @Input('data') data!: any; constructor() {} ngOnInit(): void {} whenComponentRerendered() { console.log('child component rerendered'); } changeValue() { this.data.value = 5; } }
 <p> The value from parent is {{ data | json }} </p>

No pude obtener los cambios ya que los datos no son un valor de entrada. ¿Cómo obtener cambios en el niño? Nota de StackBlitz : este es solo un código de muestra, en datos realistas tiene una gran cantidad de matrices de objetos con múltiples jerarquías.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Eliminar changeDetection: ChangeDetectionStrategy.OnPush de SamplechildComponent . Entonces funciona bien. Debe usar el sistema de detección de cambio angular changeDetection .

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!