Can someone explain the difference between Angular 10.0's ViewChild and ContentChild decorators and when to use each?
Angular 10 View Child and Content Child
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Can someone explain the difference between Angular 10.0's ViewChild and ContentChild decorators and when to use each?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Subarta RayRank #336 · 7.4K reputationPosted Feb 25, 2024, 6:21 AM EST
ViewChild and ContentChild are Angular decorators used to access child components or elements within a parent component's template. ViewChild is used to access elements or components within the parent's template, while ContentChild accesses projected content inside the parent component's projected content slots (ng-content). Use ViewChild for direct child components/elements, and ContentChild for projected content manipulation.
In the attached code snippet example:
directly.of the parent component ().