
Angular Viewchild
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-codeInstalls 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- Angular Cypress172
- Angular Router172
- Angular Control Flow170
- Angular Zoneless170
- Nx170
- Angular Signals Http169
- Angular Ssr168
- Angular Injector165
- Angular Query160
- Shadcn Ng152
- Angular Tailwind245
- Angular Material233
- Rxjs214
- Angular Security211
- Angular Bootstrap205
- Angular Cdk201
- Angular Testing197
- Ngrx195
- Angular Animations194
- Angular I18n194
- Angular Services193
- Angular Performance192
- Angular Jest190
- Angular Pwa190