AI Generate Angular docs instantly

Angular Cheat Sheet

Quick reference guide with copy-paste ready code snippets

Try DocuWriter Free

Components

3 snippets

Building blocks of Angular apps

Standalone Component

@Component({
  selector: 'app-hello',
  standalone: true,
  imports: [CommonModule],
  template: `<h1>Hello {{ name() }}</h1>`,
})
export class HelloComponent {
  name = input<string>('World');
}

Signals

count = signal(0);
double = computed(() => this.count() * 2);

increment() { this.count.update(n => n + 1); }
reset() { this.count.set(0); }

constructor() {
  effect(() => console.log('Count:', this.count()));
}

Input / Output

// Signal-based (modern)
title = input.required<string>();
onSave = output<Post>();

// Decorator-based (classic)
@Input() title: string;
@Output() onSave = new EventEmitter<Post>();

Templates

3 snippets

Template syntax and directives

Binding

<!-- Interpolation -->
<p>{{ title }}</p>
<!-- Property -->
<img [src]="imageUrl" />
<!-- Event -->
<button (click)="save()">Save</button>
<!-- Two-way -->
<input [(ngModel)]="name" />

Control Flow (new)

@if (user()) {
  <p>Hello {{ user().name }}</p>
} @else {
  <p>Please log in</p>
}

@for (item of items(); track item.id) {
  <li>{{ item.name }}</li>
} @empty {
  <li>No items</li>
}

Pipes

{{ price | currency:'USD' }}
{{ date | date:'mediumDate' }}
{{ name | uppercase }}
{{ items | async }}
{{ data | json }}

Services & DI

2 snippets

Dependency injection

Injectable Service

@Injectable({ providedIn: 'root' })
export class UserService {
  private http = inject(HttpClient);

  getUsers() {
    return this.http.get<User[]>('/api/users');
  }
}

inject()

export class UserComponent {
  private userService = inject(UserService);
  private router = inject(Router);
  users = toSignal(this.userService.getUsers());
}

Tired of looking up syntax?

DocuWriter.ai generates documentation and explains code using AI.

Try Free

Routing

3 snippets

Navigation and route config

Routes

export const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'posts/:id', component: PostComponent },
  { path: 'admin', loadComponent: () =>
    import('./admin/admin.component').then(m => m.AdminComponent),
    canActivate: [authGuard]
  },
  { path: '**', redirectTo: '' },
];

Router Link

<a routerLink="/posts" routerLinkActive="active">Posts</a>
<a [routerLink]="['/posts', post.id]">{{ post.title }}</a>

Programmatic

private router = inject(Router);
this.router.navigate(['/posts', id]);
this.router.navigate(['/search'], { queryParams: { q: 'angular' } });

Reactive Forms

3 snippets

Form handling with FormBuilder

FormGroup

private fb = inject(FormBuilder);
form = this.fb.group({
  name: ['', [Validators.required, Validators.minLength(3)]],
  email: ['', [Validators.required, Validators.email]],
  role: ['user'],
});

Template

<form [formGroup]="form" (ngSubmit)="onSubmit()">
  <input formControlName="name" />
  @if (form.get('name')?.errors?.['required']) {
    <span>Name required</span>
  }
  <button [disabled]="form.invalid">Submit</button>
</form>

Submit

onSubmit() {
  if (this.form.valid) {
    const data = this.form.getRawValue();
    this.userService.create(data).subscribe();
  }
}

HTTP Client

2 snippets

API calls and interceptors

GET / POST

private http = inject(HttpClient);

getPosts(): Observable<Post[]> {
  return this.http.get<Post[]>('/api/posts');
}

createPost(data: PostDTO): Observable<Post> {
  return this.http.post<Post>('/api/posts', data);
}

Interceptor

export const authInterceptor: HttpInterceptorFn = (req, next) => {
  const token = inject(AuthService).getToken();
  const authReq = req.clone({
    setHeaders: { Authorization: 'Bearer ' + token }
  });
  return next(authReq);
};

More Cheat Sheets

FAQ

Frequently asked questions

What is a Angular cheat sheet?

A Angular cheat sheet is a quick reference guide containing the most commonly used syntax, functions, and patterns in Angular. It helps developers quickly look up syntax without searching through documentation.

How do I learn Angular quickly?

Start with the basics: variables, control flow, and functions. Use this cheat sheet as a reference while practicing. For faster learning, try DocuWriter.ai to automatically explain code and generate documentation as you learn.

What are the most important Angular concepts?

Key Angular concepts include variables and data types, control flow (if/else, loops), functions, error handling, and working with data structures like arrays and objects/dictionaries.

How can I document my Angular code?

Use inline comments for complex logic, docstrings for functions and classes, and README files for projects. DocuWriter.ai can automatically generate professional documentation from your Angular code using AI.

Related resources

Stop memorizing. Start shipping.

Generate Angular Docs with AI

DocuWriter.ai automatically generates comments, docstrings, and README files for your code.

Auto-generate comments
Create README files
Explain complex code
API documentation
Start Free - No Credit Card

Join 33,700+ developers saving hours every week