Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Angular FAQ: Top Questions

31. What is the difference between ViewChild and ContentChild?

@ViewChild and @ContentChild are decorators used to access child components or DOM elements.

  • @ViewChild: Access elements from the component’s own view template.
  • @ContentChild: Access elements projected into the component using ng-content.

@ViewChild('myDiv') div: ElementRef;
@ContentChild('projectedContent') content: ElementRef;