Components, DI, RxJS, change detection, signals
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeProperty binding sets a DOM property or component input using square brackets, like [value]="user.name". Event binding listens for events using parentheses, like (click)="save()". Property binding flows data from component to view, while event binding flows data from view to component.
You inject a service by declaring it as a parameter in the component's constructor and marking it as private or public, for example: constructor(private userService: UserService) {}. Angular's DI system provides the instance automatically.
An observable is a stream of asynchronous data that you can subscribe to. In Angular, observables are used for things like HTTP requests or form value changes, allowing you to react to new data over time.
The async pipe subscribes to an observable or promise and automatically updates the view with the latest value. It also handles unsubscribing when the component is destroyed, preventing memory leaks.
Reactive forms are defined in TypeScript and use explicit form controls, making them more scalable, testable, and suitable for complex validation or dynamic forms. Template-driven forms are simpler, using directives in the template, and are best for basic forms with minimal logic.
I either unsubscribe manually in the ngOnDestroy lifecycle hook or use the async pipe in templates. For multiple subscriptions, I often use the takeUntil operator with a subject that emits on destroy.
OnPush tells Angular to check a component only when its inputs change by reference, or when an event occurs inside the component. It's ideal for performance optimization, especially in large apps or when using immutable data.
You implement a guard by creating a service that implements interfaces like CanActivate or CanLoad, and returning a boolean or observable. Common use cases include protecting routes from unauthorized access or checking if data is loaded before navigation.
HttpClient makes HTTP requests and returns observables. You can subscribe to these observables to get the response, and use RxJS operators to transform or handle errors. It also supports interceptors for cross-cutting concerns.
TestBed sets up a testing module that mimics the Angular environment, allowing you to declare components, provide services, and configure dependencies for unit and integration tests. It helps isolate what you're testing and ensures consistency.
You use the loadChildren property in the route definition, pointing to a dynamic import of the module. For example: { path: 'admin', loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule) }.
You implement the HttpInterceptor interface, clone the request to add the token in the headers, and pass it to next.handle(). This ensures all outgoing requests include the token without modifying each service.