What are Angular services, and how do you use them?
Answer: Angular services are singleton objects that encapsulate business logic and data sharing across components. They’re created with the @Injectable decorator and provided via dependency injection.
Explain the difference between ngOnInit() and a constructor in Angular.
Answer: The constructor is for initializing class members, while ngOnInit() is a lifecycle hook where you should fetch data or run code once the component’s view is ready.
How does Angular handle two-way data binding?
Answer: Angular uses the [(ngModel)] directive for two-way data binding, syncing the model and view by combining property binding and event binding.
What is lazy loading in Angular, and why is it useful?
Answer: Lazy loading loads feature modules only when they’re needed, reducing initial load time and improving performance.
Explain the difference between @Input() and @Output() decorators.
Answer: @Input() allows passing data from a parent to a child component, while @Output() emits events from a child to a parent component.
Top comments (0)