At which lifecycle hook is it best to make an HTTP request in an Angular component?
- constructor
- ngAfterViewInit
- ngOnDestroy
- ngOnInit
In Angular, it's best to use the ngOnInit lifecycle hook to handle any additional initialization tasks, including making HTTP requests. The constructor is mainly used for dependency injection and not for logic.
Loading...
Related Quiz
- What method of HttpClient would you use to send a GET request?
- Which providedIn value ensures that a service instance is shared across the entire application?
- For handling offline data synchronization in an Angular app, which RxJS operator would be most appropriate?
- In NgRx, what would you use to handle side effects like API calls?
- What is the significance of the RouterLinkActive directive?