Angular in interviews
Interviewers check whether you can build and reason about a component-based app: how data flows between components, where logic lives, and how the framework updates the screen.
- Components & templatesDecorators, binding and control flow.
- Services & DISharing logic and data cleanly.
- Routing & RxJSNavigation, lazy loading and Observables.
Angular (version 2 and later, written in TypeScript) is a common requirement for front-end and full-stack roles. These questions cover the basics interviewers ask most, with short TypeScript examples that match current Angular versions.
1. What is Angular and how is it different from AngularJS?
Angular is a TypeScript-based framework from Google for building single-page applications. AngularJS (version 1.x) used JavaScript, controllers and two-way binding everywhere. Angular (2 and later) is a complete rewrite built around components, TypeScript, dependency injection and a faster change-detection system. AngularJS reached end of life in 2021.
2. What is a component?
A component is the basic building block of an Angular UI: a TypeScript class with a @Component decorator that links it to an HTML template and styles. Each component controls one part of the screen.
@Component({
selector: 'app-course-card',
standalone: true,
template: `<h3>{{ title }}</h3><button (click)="enroll()">Enroll</button>`
})
export class CourseCardComponent {
title = 'Angular Basics';
enroll() { console.log('Enrolled in', this.title); }
}3. What are NgModules and standalone components?
Earlier versions grouped components, directives and pipes into NgModules. Since Angular 14 (and by default in newer versions), components can be standalone: they declare their own imports and do not need a module. New projects mostly use standalone components; older projects still use modules, so you should understand both.
4. Explain the types of data binding.
Interpolation {{ value }} displays data. Property binding [src]="url" sets element properties. Event binding (click)="save()" responds to user actions. Two-way binding [(ngModel)]="name" combines property and event binding, mostly for forms.
<input [(ngModel)]="name" />
<p>Hello {{ name }}</p>
<img [src]="avatarUrl" (click)="openProfile()" />5. What are directives? Name the types.
Directives add behaviour to elements. Components are directives with a template. Structural directives change the DOM layout (*ngIf, *ngFor, or the newer @if and @for control flow). Attribute directives change appearance or behaviour (ngClass, ngStyle, or custom ones).
@for (course of courses; track course.id) {
<app-course-card [title]="course.title" />
} @empty {
<p>No courses yet.</p>
}6. What is a service and what is dependency injection?
A service is a class that holds logic or data shared across components, such as API calls. Dependency injection means Angular creates the service and supplies it to whoever needs it, instead of each component creating its own copy. This makes code reusable and easy to test.
@Injectable({ providedIn: 'root' })
export class CourseService {
private http = inject(HttpClient);
getCourses() { return this.http.get<Course[]>('/api/courses'); }
}7. What are lifecycle hooks? Which are used most?
Lifecycle hooks let you run code at specific moments in a component’s life. ngOnInit runs once after inputs are set — the usual place to load data. ngOnChanges runs when an input changes. ngOnDestroy runs before the component is removed — used to unsubscribe and clean up. Others include ngAfterViewInit and ngDoCheck.
8. How does routing work in Angular?
The router maps URL paths to components. You define routes, place <router-outlet> where the page should render, and navigate with routerLink or the Router service. Routes can be lazy-loaded so their code downloads only when needed.
export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: 'courses/:id', component: CourseDetailComponent },
{ path: 'admin', loadComponent: () => import('./admin.component').then(m => m.AdminComponent) },
];9. What is an Observable and how is it different from a Promise?
An Observable (from RxJS) represents a stream of values over time; a Promise represents a single future value. Observables are lazy (nothing happens until you subscribe), can emit many values, can be cancelled by unsubscribing, and have operators like map, filter and switchMap. Angular’s HttpClient returns Observables.
Remember
Key points
- Inputs down, events up
Parents pass data with @Input / input(); children notify parents with @Output events.
- Unsubscribe
Clean up long-lived subscriptions in ngOnDestroy or use the async pipe.
- Standalone first
New Angular apps use standalone components; modules are still common in older code.
Interview drill
Follow-up questions
What the interviewer asks after your first answer. Turn on practice mode, answer each one aloud, then reveal.
-
1 How do you pass data from a parent to a child component and back? Basic
Parent to child: an
@Input()property (or a signal-basedinput()). Child to parent: an@Output()EventEmitter(oroutput()) that the parent listens to. For unrelated components, use a shared service.// child @Input() title = ''; @Output() selected = new EventEmitter<string>(); // parent template <app-course-card [title]="c.title" (selected)="open($event)" />Key insight: Inputs down, outputs up, services sideways.
-
2 What is the async pipe and why use it? Intermediate
The
asyncpipe subscribes to an Observable or Promise in the template and automatically unsubscribes when the component is destroyed. It avoids memory leaks and manual subscription code.courses$ = this.courseService.getCourses(); // template @for (c of courses$ | async; track c.id) { <p>{{ c.title }}</p> }Key insight: Let the template manage the subscription.
-
3 What is change detection and what does OnPush do? Advanced
Change detection is how Angular checks whether data has changed and updates the view. By default it checks every component after events. With
ChangeDetectionStrategy.OnPush, a component is checked only when its inputs change by reference, an event happens inside it, or an Observable bound withasyncemits — which improves performance in large apps.Key insight: OnPush + immutable data = fewer, cheaper checks.
-
4 What is the difference between switchMap and mergeMap? Advanced
switchMapcancels the previous inner Observable when a new value arrives — ideal for search boxes.mergeMapruns all inner Observables in parallel and merges their results — useful when every request must complete.this.search.valueChanges.pipe( debounceTime(300), switchMap(q => this.api.search(q)) // only the latest search matters );Key insight: Typeahead search: switchMap. Independent saves: mergeMap or concatMap.
-
5 What are pipes? Give an example of a custom pipe. Basic
Pipes transform values for display in templates, such as
date,currencyanduppercase. A custom pipe implementsPipeTransform.@Pipe({ name: 'initials', standalone: true }) export class InitialsPipe implements PipeTransform { transform(name: string) { return name.split(' ').map(p => p[0]).join(''); } }Key insight: Pure pipes run only when their input changes — cheap and cacheable.