An Angular service is used to share business logic or data between components. Instead of repeating the same logic everywhere, you put it in a service. Real-life example: a shared power socket—multiple devices use the same source instead of each having their own generator.
Interview Flashcards & Mock Mode
Practice with 3D flip cards, voice reader, and timed interview simulations.
CodeShot.in — Daily Challenges
60-second in-browser coding micro-challenges to sharpen syntax and problem-solving speed.
What is a service in Angular and why do we use it?
What is lazy loading in Angular and why is it useful?
Lazy loading means loading Angular modules only when they are needed instead of loading everything upfront. It’s like opening apps on your phone only when you tap them. This reduces initial load time and improves performance in large applications.
How do you implement lazy loading in Angular?
Lazy loading is implemented using Angular routing with loadChildren. Routes are configured so that modules load only when the user navigates to them.
When should you avoid lazy loading?
Lazy loading should be avoided for very small applications or core features that are always needed, because it may add unnecessary complexity and extra network calls.
What is a pipe in Angular?
A pipe transforms data in Angular templates without changing the underlying value. It’s like applying a filter on a photo—it changes how it looks, not the photo itself.
What is the difference between pure and impure pipes?
Pure pipes run only when input values change, making them performant. Impure pipes run on every change detection cycle and should be used carefully.
What is Change Detection in Angular and how does it work?
Change Detection is Angular's mechanism to detect when component data has changed and update the DOM accordingly. By default, Angular checks every component on every event. It's like a security guard scanning every person—thorough but slow for large apps. Using OnPush strategy tells Angular to check only when inputs change.
What is OnPush change detection strategy?
OnPush tells Angular to only run change detection when the component's input references change or an event triggers within the component. It significantly improves performance in large applications.
How does ChangeDetectorRef help in Angular?
ChangeDetectorRef lets you manually control change detection—triggering it explicitly or detaching it to prevent unnecessary checks. Useful in real-time data scenarios where you want fine-grained control.
What is the difference between Promise and Observable in Angular/Node.js?
A Promise handles a single future value and executes immediately. An Observable handles a stream of values over time and is lazy—it only executes when subscribed to. Think of a Promise as a one-time food delivery and an Observable as a subscription meal service that keeps delivering.
Can you cancel an Observable but not a Promise?
Yes. Observables can be unsubscribed, effectively cancelling them. Promises cannot be cancelled once started. This makes Observables more flexible for scenarios like search-as-you-type where old requests should be dropped.