Skip to content

Coding practice

Angular Coding Questions

15 hands-on challenges with prompts and solution sketches for Angular interview rounds.

Challenge set

15 coding questions

1. Standalone Component

typescript

Declare a standalone Angular component.

@Component({
  selector: "app-hello",
  standalone: true,
  template: `<p>Hello {{ name }}</p>`,
})
export class HelloComponent {
  name = "Angular";
}

2. Input Signal

typescript

Accept an input with input().

import { Component, input } from "@angular/core";
export class CardComponent {
  title = input.required<string>();
}

3. Output Event

typescript

Emit an event with output().

import { output } from "@angular/core";
export class SaveButton {
  saved = output<void>();
  onClick() {
    this.saved.emit();
  }
}

4. HttpClient Get

typescript

Fetch users with HttpClient.

constructor(private http: HttpClient) {}
load() {
  return this.http.get<User[]>("/api/users");
}

5. Reactive Form

typescript

Build a FormGroup with validators.

form = new FormGroup({
  email: new FormControl("", [Validators.required, Validators.email]),
});

6. Route Param

typescript

Read an id route param.

id = inject(ActivatedRoute).snapshot.paramMap.get("id");

7. Async Pipe List

html

Render an observable list with async pipe.

<li *ngFor="let user of users$ | async">{{ user.name }}</li>

8. Dependency Injection

typescript

Inject a service with inject().

private readonly api = inject(ApiService);

9. Computed Signal

typescript

Derive a value with computed().

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

10. Structural Directive Usage

html

Conditionally render with @if.

@if (user) {
  <p>{{ user.name }}</p>
} @else {
  <p>Guest</p>
}

11. Track By

html

Use track in @for.

@for (item of items; track item.id) {
  <div>{{ item.label }}</div>
}

12. Interceptor Stub

typescript

Add an auth header interceptor.

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

13. CanActivate Guard

typescript

Protect a route with a functional guard.

export const authGuard: CanActivateFn = () => {
  return inject(AuthService).isLoggedIn() || inject(Router).parseUrl("/login");
};

14. OnPush Change Detection

typescript

Set OnPush change detection.

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  // ...
})
export class FastComponent {}

15. Destroy Ref Cleanup

typescript

Clean up a subscription with DestroyRef.

const destroyRef = inject(DestroyRef);
const sub = source$.subscribe();
destroyRef.onDestroy(() => sub.unsubscribe());