| technology | Angular | |||||
|---|---|---|---|---|---|---|
| domain | frontend | |||||
| level | Senior/Architect | |||||
| version | 20+ | |||||
| tags |
|
|||||
| ai_role | Senior Angular Expert | |||||
| last_updated | 2026-04-05 |
Note
Context: Component State Management
private count$ = new BehaviorSubject(0);
getCount() { return this.count$.value; }RxJS is overkill for simple synchronous state. BehaviorSubject requires .value for access and .next() for writes, increasing cognitive load.
count = signal(0);
// Access: count()
// Update: count.set(1)Use signal() for local state. It is a primitive designed specifically for synchronizing UI and data.
Note
Context: Reactivity
ngOnChanges(changes: SimpleChanges) {
if (changes['firstName']) {
this.fullName = `${this.firstName} ${this.lastName}`;
}
}ngOnChanges is triggered only when Inputs change, has complex typing, and runs before View initialization.
fullName = computed(() => `${this.firstName()} ${this.lastName()}`);Use computed(). The signal is recalculated only when its dependencies change, and the result is memoized (cached).
Note
Context: DI Pattern
constructor(private http: HttpClient, private store: Store) {}Constructors become cluttered with many dependencies. When inheriting classes, dependencies must be passed through super().
private http = inject(HttpClient);
private store = inject(Store);Use the inject() function. It operates in the initialization context (fields or constructor), is type-safe, and does not require super() during inheritance.
Note
Context: App Architecture
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule]
})
export class AppModule {}Modules create an unnecessary level of indirection. Components become dependent on the module context, complicating Lazy Loading and testing.
@Component({
standalone: true,
imports: [CommonModule]
})Use Standalone Components. This is the Angular v14+ standard that makes components self-sufficient and tree-shakable.
Note
Context: Lazy Loading Routing
loadChildren: () => import('./module').then(m => m.UserModule)Loading modules pulls in transitive dependencies that might not be needed.
loadComponent: () => import('./user.component').then(c => c.UserComponent)