This one handles Angular's ViewChild, ContentChild, and related DOM query decorators. Use it when you need to access child components, DOM elements, or projected content in your Angular components. It covers the static option timing (ngOnInit vs ngAfterViewInit), the read parameter for specifying what type to extract, and QueryList for multiple elements. The examples show real patterns like focusing inputs, accessing component methods, and working with ViewContainerRef for dynamic content. It's updated for Angular 21 and includes signal integration patterns. Honestly a solid reference if you keep forgetting when to use static true or how ContentChild differs from ViewChild for ng-content scenarios.

skills.sh installs
174
GitHub stars
7
last updated
Aug 21, 2026

Install

$ npx -y skills add oguzhan18/angular-ecosystem-skills --skill angular-viewchild --agent claude-code

Installs into .claude/skills of the current project.

Files

Angular ViewChild / ContentChild

Version: Angular 21 (2025) Tags: ViewChild, ContentChild, DOM, Queries

References: ViewChild API • ContentChild API

Best Practices

  • Use ViewChild for element reference
import { ViewChild, ElementRef, AfterViewInit } from '@angular/core';

@Component({})
export class MyComponent implements AfterViewInit {
  @ViewChild('input') inputEl!: ElementRef<HTMLInputElement>;
  
  ngAfterViewInit() {
    this.inputEl.nativeElement.focus();
  }
}
  • Use static option
// Static - available in ngOnInit
@ViewChild('static', { static: true }) staticEl!: ElementRef;

// Dynamic - available in ngAfterViewInit
@ViewChild('dynamic', { static: false }) dynamicEl!: ElementRef;
  • Use ContentChild for projected content
import { ContentChild, TemplateRef } from '@angular/core';

@Component({
  selector: 'app-card',
  template: `
    <div class="card">
      <ng-content></ng-content>
    </div>
  `
})
export class CardComponent {
  @ContentChild(TemplateRef) headerTemplate!: TemplateRef<any>;
}

Sponsors

Details

Repository
github.com/oguzhan18/angular-ecosystem-skills
Category
Frontend Development
First seen
Jun 3, 2026

More from oguzhan18/angular-ecosystem-skills

All 45
1andrelandgraf avatarnextjs-on-vercelandrelandgraf/fullstackrecipesCreate a Next.js app running on Bun, configure the development environment, and deploy to Vercel with automatic deployments on push.164skills.sh installs
2posthog avatarfeature-flags-nextjsposthog/skillsPostHog feature flags for Next.js applications139skills.sh installs
3huangjia2019 avatarReact 最佳实践huangjia2019/claude-code-engineeringReact 组件设计模式、Hooks 使用指南、性能优化技巧0skills.sh installs
4kettleofketchup avatarfrontend-dev-guidelineskettleofketchup/DraftForgeFrontend development guidelines for React/TypeScript applications. Modern patterns including Suspense, lazy loading, useSuspenseQuery, file organization with fe0skills.sh installs
5recomby-ai avatargeo-review-htmlrecomby-ai/recomby-geoRender an interactive, self-contained HTML companion for a GEO content brief (04-content-brief) or a publish-ready draft (05-production), so a NON-technical cli0skills.sh installs
6TheOrcDev avatarrerender-memoTheOrcDev/8bitcn-uiExtract expensive work into memoized components with React.memo. Apply when components perform expensive computations that can be skipped when props haven't cha0skills.sh installs