Can someone explain the difference between Angular 10.0's ViewChild and ContentChild decorators and when to use each?
Loading
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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Subarta RayPosted Feb 25, 2024, 11:21 AM
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 ().