Get familiar with key Angular 16+ concepts using real-world scenarios. Perfect for brushing up on directives, forms, pipes, and more before your next interview.
Which of the following is NOT a type of Angular directive?
Explanation: Component, Structural, and Attribute are the three types of Angular directives. Service is a separate concept used for business logic and dependency injection, not a directive. The other options are correct directive types.
Why is ngOnInit() preferred over the constructor for initialization logic in Angular components?
Explanation: ngOnInit() runs after the component's inputs are initialized, making it ideal for startup logic or API calls. Constructors are for injecting services, not for running initialization code that depends on inputs. The other options misrepresent their purposes.
When would you choose Observables over Promises in an Angular application?
Explanation: Observables are ideal for real-time updates, like chats or dynamic data streams. Promises suit single, one-off operations. Synchronous data does not require either, and lazy loading concerns modules, not Observables directly.
Which Angular form type is best for handling complex and dynamic form controls?
Explanation: Reactive Forms are recommended for dynamic and complex scenarios due to their flexibility and structure. Template-Driven Forms fit simple cases. HTML Forms lack Angular's features, and 'Reactive Directives' is not a real form type.
What is the main function of *ngFor in Angular templates?
Explanation: *ngFor is used to loop over collections and render multiple elements. *ngIf handles conditional rendering, switching classes is done with directives like ngClass, and dependency injection is unrelated.
How does ViewChild differ from ContentChild in Angular?
Explanation: ViewChild retrieves elements defined in the component's own template, while ContentChild is for accessing elements passed via <ng-content>. The other options are inaccurate or incorrect.
What is the primary use of pipes in Angular templates?
Explanation: Pipes are used to format and transform data directly in templates, like formatting dates or currency. Pipes do not inject dependencies, handle HTTP requests, or create form controls.
Which feature does Angular's HttpClient module NOT provide?
Explanation: HttpClient is used for HTTP operations, error handling, and features like HttpInterceptor. Compiling templates is handled by Angular's compiler, not by HttpClient.
What does Angular's lazy loading allow you to do?
Explanation: Lazy loading defers loading of feature modules until they are required, improving app performance. It does not compile styles, run tests, or load everything at once.
Which of the following is a common Angular CLI command for generating a new component?
Explanation: The Angular CLI uses 'ng generate component login' to create a new component. The other commands are invalid or serve different purposes not associated with component creation.