angular-viewchild
ALWAYS use when working with Angular ViewChild, ContentChild, ViewChildren, or accessing DOM elements and child components in Angular.
Works with
Agent Skills format with YAML frontmatter. Claude Code reads it as-is.
---
name: "angular-viewchild"
description: "ALWAYS use when working with Angular ViewChild, ContentChild, ViewChildren, or accessing DOM elements and child components in Angular."
license: "MIT"
---
# Angular ViewChild / ContentChild
**Version:** Angular 21 (2025)
**Tags:** ViewChild, ContentChild, DOM, Queries
**References:** [ViewChild API](https://angular.io/api/core/ViewChild) • [ContentChild API](https://angular.io/api/core/ContentChild)
## Best Practices
- Use ViewChild for element reference
```ts
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
```ts
// 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
```ts
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>;
}
```
- Use ViewChildren for multiple elements
```ts
import { ViewChildren, QueryList } from '@angular/core';
@Component({})
export class ListComponent {
@ViewChildren('item') items!: QueryList<ElementRef>;
ngAfterViewInit() {
this.items.forEach(item => console.log(item));
}
}
```
- Use read option
```ts
@ViewChild('component', { read: ViewContainerRef }) container!: ViewContainerRef;
@ViewChild('template', { read: TemplateRef }) template!: TemplateRef<any>;
```
- Access component instance
```ts
@ViewChild(ChildComponent) child!: ChildComponent;
ngAfterViewInit() {
this.child.doSomething();
}
```
- Use with signals
```ts
@ViewChild('el') el!: ElementRef<HTMLElement>;
ngAfterViewInit() {
effect(() => {
if (this.shouldFocus()) {
this.el.nativeElement.focus();
}
});
}
```More Frontend Frameworks skills
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
design-taste-frontend
leonxlnx/taste-skill
Anti-slop frontend skill for landing pages, portfolios, and redesigns. The agent reads the brief, infers the right design direction, and ships interfaces that do not look templated. Real design systems when applicable, audit-first on redesigns, strict pre-flight check.
hyperframes-creative
heygen-com/hyperframes
Non-animation creative direction for HyperFrames videos. Use for design spec (frame.md / design.md) handling, palettes, typography, narration, beat planning, audio-reactive visuals, composition patterns, and brand / style decisions. For atomic motion patterns and scene blueprints, use hyperframes-animation.

