Angular
Platform for building mobile and desktop web applications.
Interview Questions
25 TotalWhat is the purpose of the Angular CLI?
The Angular CLI is a command-line interface tool that allows developers to create, build, and serve Angular applications.
How do you handle errors in Angular?
Angular provides an ErrorHandler class that can be used to catch and handle errors. You can also use try-catch blocks and the async pipe to handle errors in templates.
What is the difference between a component and a directive in Angular?
A component is a self-contained piece of UI, while a directive is an attribute that can be applied to an existing element to extend its behavior.
How do you implement routing in Angular?
Angular provides a RouterModule that can be used to configure routes. You can define routes using the @NgModule decorator and the Routes array.
What is a service in Angular and how is it used?
A service is a class that provides a specific functionality that can be used by multiple components. Services are typically used to share data between components or to encapsulate business logic.
How do you inject a service into a component in Angular?
You can inject a service into a component using the constructor and the @Inject decorator. The service must be provided in the component's module or a parent module.
What is the difference between the ngOnInit and ngAfterViewInit lifecycle hooks in Angular?
The ngOnInit hook is called after the component's properties have been initialized, while the ngAfterViewInit hook is called after the component's view has been initialized.
How do you use the async pipe in Angular?
The async pipe can be used to subscribe to observables in templates. It automatically unsubscribes when the component is destroyed.
What is the purpose of the ChangeDetectionStrategy in Angular?
The ChangeDetectionStrategy determines how Angular detects changes to a component's properties. The default strategy is ChangeDetectionStrategy.Default.
How do you implement a custom pipe in Angular?
A custom pipe can be implemented by creating a class that implements the PipeTransform interface. The pipe must be declared in the @NgModule decorator.
What is the difference between a subject and a behavior subject in Angular?
A subject is a basic implementation of the observer pattern, while a behavior subject is a subject that stores the current value and emits it to new subscribers.
How do you use the HttpClient in Angular?
The HttpClient can be used to make HTTP requests. It provides methods such as get, post, put, and delete.
What is the purpose of the TestBed in Angular?
The TestBed is a testing utility that provides a way to configure and create a testing module. It can be used to test components, services, and pipes.
How do you test a component in Angular?
A component can be tested using the TestBed and the Jasmine testing framework. You can write unit tests to test the component's properties and methods.
What is the difference between a template-driven form and a model-driven form in Angular?
A template-driven form uses template markup to define the form, while a model-driven form uses a model to define the form.
How do you validate a form in Angular?
Forms can be validated using validators such as required, minlength, and maxlength. You can also create custom validators.
What is the purpose of the ng-container directive in Angular?
The ng-container directive is a grouping element that can be used to apply structural directives without adding an extra element to the DOM.
How do you use the ngClass directive in Angular?
The ngClass directive can be used to apply CSS classes to an element based on a condition.
What is the purpose of the ngStyle directive in Angular?
The ngStyle directive can be used to apply inline styles to an element based on a condition.
How do you implement internationalization in Angular?
Internationalization can be implemented using the LOCALE_ID token and the translate pipe.
What is the difference between the CanActivate and CanActivateChild guards in Angular?
The CanActivate guard determines whether a route can be activated, while the CanActivateChild guard determines whether a child route can be activated.
How do you implement a custom guard in Angular?
A custom guard can be implemented by creating a class that implements the CanActivate interface. The guard must be provided in the component's module or a parent module.
What is the purpose of the Ivy compiler in Angular?
The Ivy compiler is a next-generation compiler that provides faster compilation and smaller bundle sizes.
How do you use the ComponentStore in Angular?
The ComponentStore is a state management utility that provides a way to manage global state. It can be used to share data between components.
What is the difference between the standalone and non-standalone components in Angular?
Standalone components are self-contained components that do not require a module, while non-standalone components require a module.