State Management — Angular Technical Interview Questions & Answers
State Management
State Management
- State: start with a service + BehaviorSubject or signals. NgRx / a store is for many screens sharing complex flows. Don’t put every click in the store.
- Board: cart count in a root service. Header and cart page both select it. Trap: NgRx tutorial copy-paste for a two-page campus app.
Technical Interview Tip: Service + subject vs when NgRx is worth it.
Code Examples for State Management
State Management — working example
import { Component } from "@angular/core";
@Component({
selector: "app-root",
template: `
<h1>{{ title }}</h1>
<button (click)="toggle()">Toggle</button>
<p *ngIf="open">Panel open</p>
`,
})
export class AppComponent {
title = "Angular practice";
open = true;
toggle() {
this.open = !this.open;
}
}State Management: toggle open. Say whether the panel is on screen after one click.
How to Explain State Management to an Interviewer
When do you need NgRx?
Many screens Hard shared flows Not every click