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

196
Views
¿Cómo puedo usar ContentChild/Children en <ng-content> anidado?

Estoy usando con éxito <ng-content></ng-content> para mostrar un componente en un nieto como se responde aquí: árbol de componentes de padre a hijo con componente invitado , pero ahora me gustaría usar @ContentChild en ese nieto para acceder al contenido pasado, pero parece que no puedo hacer que nada funcione.

Aquí está mi intento de usar un selector y @ContentChild en un stackBlitz: https://stackblitz.com/edit/angular-dpu4pm . No importa lo que haga, @ContentChild siempre está indefinido en el componente TheChild, pero funciona en el componente TheParent.

 @Component({ selector: 'spinner', template: ` spinner `, }) @Component({ selector: 'my-app', template: ` works <the-parent><spinner #spin></spinner></the-parent> `, }) @Component({ selector: 'the-parent', template: 'this is parent <the-child><ng-content #content></ng-content></the-child>' }) export class TheParent implements AfterViewInit{ @ContentChild('spin') spin; ngAfterViewInit() { alert('parents spin is '+typeof this.spin); //object } } @Component({ selector: 'the-child', template: 'this is child <ng-content></ng-content>' }) export class TheChild implements AfterViewInit{ @ContentChild('spin') spin; @ContentChild('content') content; ngAfterViewInit() { alert('childs spin is '+typeof this.spin); //undefined alert('childs content is '+typeof this.content); //undefined } }

Cualquier consejo sobre cómo hacer que esto funcione, o cualquier otro enfoque para acceder al abuelo del nieto sería muy apreciado.

over 4 years ago · Santiago Trujillo
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!