{"id":136367,"date":"2024-07-08T15:46:24","date_gmt":"2024-07-08T15:46:24","guid":{"rendered":"https:\/\/www.sushilkumar.ind.in\/blog\/?p=136367"},"modified":"2024-07-08T16:00:22","modified_gmt":"2024-07-08T16:00:22","slug":"top-angular-interview-questions-and-answers","status":"publish","type":"post","link":"https:\/\/www.sushilkumar.ind.in\/blog\/angular\/top-angular-interview-questions-and-answers\/","title":{"rendered":"Top Angular interview questions and answers"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. What is Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular is a platform and framework for building single-page client applications using HTML and TypeScript. It is developed and maintained by Google.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. What is TypeScript?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: TypeScript is a superset of JavaScript that adds static typing to the language. Angular applications are written in TypeScript.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. What are Angular components?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Components are the fundamental building blocks of Angular applications. They control a patch of screen called a view.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. What is a module in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A module is a container for a group of related components, services, directives, and pipes. An Angular application is defined by a set of NgModules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. What is a directive in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Directives are classes that add additional behavior to elements in your Angular applications. There are three types: components, attribute directives, and structural directives.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. What are services in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Services are singleton objects that are used to organize and share code across the application. They can be injected into components and other services.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. What is Dependency Injection in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Dependency Injection (DI) is a design pattern in which a class requests dependencies from external sources rather than creating them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. What is Angular CLI?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular CLI (Command Line Interface) is a tool to initialize, develop, scaffold, and maintain Angular applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. What is a template in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A template in Angular is a piece of HTML that tells Angular how to render the component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. What is data binding in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Data binding is a mechanism to synchronize data between the model and the view. Angular supports one-way, two-way, and event binding.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">11. What is Angular routing?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular routing is a feature that enables navigation from one view to the next as users perform application tasks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">12. What are Angular Pipes?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Pipes are simple functions designed to accept an input value, process it, and return a transformed value.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. What is the difference between a component and a directive?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A component is a directive with a template. Components are a special type of directive in Angular.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">14. What is the purpose of NgModule?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: NgModule is a decorator function that takes a single metadata object whose properties describe the module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. How does Angular handle events?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular provides event binding to handle events. You can bind to DOM events like click, change, or keyup using parentheses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">16. What are lifecycle hooks in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Lifecycle hooks are methods that Angular calls at specific stages of a component&#8217;s lifecycle, such as ngOnInit, ngOnChanges, ngOnDestroy, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">17. What is Angular Universal?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular Universal is a technology that allows you to run Angular applications on the server. This process is called server-side rendering (SSR).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">18. What is AOT compilation?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: AOT (Ahead-of-Time) compilation is the process of compiling Angular HTML and TypeScript code into JavaScript code during the build process, before the browser downloads and runs the code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">19. What is lazy loading in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Lazy loading is a technique in Angular to load NgModules on demand rather than all at once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">20. What is Angular Ivy?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular Ivy is the new rendering engine for Angular, designed to make applications faster and smaller.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">21. How do you create a service in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: You can create a service in Angular using the Angular CLI with the command <code>ng generate service service-name<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">22. What is Reactive Forms in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Reactive Forms provide a model-driven approach to handling form inputs whose values change over time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">23. What is the difference between Reactive Forms and Template-driven Forms?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Template-driven forms are asynchronous and easy to use, while Reactive Forms are synchronous and provide more powerful and flexible APIs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">24. How do you handle errors in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Errors can be handled in Angular using try-catch blocks, Angular&#8217;s ErrorHandler class, and observables&#8217; catchError operator.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">25. What is the purpose of the HttpClient module in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The HttpClient module is used to perform HTTP requests, allowing you to communicate with backend services over HTTP.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">26. How do you perform unit testing in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Unit testing in Angular can be performed using Jasmine and Karma, which are included in the Angular CLI setup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">27. What is Angular Material?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular Material is a UI component library for Angular developers, based on Google&#8217;s Material Design principles.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">28. What is NgRx?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: NgRx is a set of reactive extensions for Angular, inspired by Redux, that manage application state in a predictable manner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">29. What is the purpose of the ng-template directive?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The ng-template directive is used to define template content that can be reused and conditionally rendered.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">30. How do you optimize an Angular application for performance?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Performance can be optimized by lazy loading, using AOT compilation, caching, using OnPush change detection strategy, and minimizing bundle size.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">31. What is the difference between ActivatedRoute and Router?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: ActivatedRoute provides access to information about a route associated with a component that is loaded in an outlet, while Router is a service that provides navigation among views and URL manipulation capabilities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">32. What are resolvers in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Resolvers are used to pre-fetch data before navigating to a route.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">33. What is the Angular Animation module?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The Angular Animation module allows you to create advanced animation effects within your Angular applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">34. What is the purpose of the async pipe?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The async pipe subscribes to an Observable or Promise and returns the latest value it has emitted. It also marks the component to be checked for changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">35. How do you create a custom directive in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A custom directive can be created using the @Directive decorator, and you define its behavior in the directive class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">36. What is the role of the BrowserModule in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The BrowserModule is required for any web-based Angular application and contains services and directives for rendering and bootstrapping the application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">37. How do you pass data between components in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Data can be passed between components using @Input() and @Output() decorators, services, and the shared state in NgRx.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">38. What is the purpose of the Renderer2 class in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The Renderer2 class is used to manipulate DOM elements in a way that is platform-agnostic, helping with cross-browser compatibility.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">39. What is Angular&#8217;s change detection strategy?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Angular&#8217;s change detection strategy determines how the framework checks for updates to the component&#8217;s data. The default strategy is <code>CheckAlways<\/code>, and the alternative is <code>OnPush<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">40. How do you implement route guards in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Route guards are implemented by creating services that implement the CanActivate, CanActivateChild, CanLoad, CanDeactivate, or Resolve interfaces.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">41. What is a resolver in Angular routing?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A resolver is used to pre-fetch data before activating a route, ensuring the data is available as soon as the route is activated.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">42. How do you share data between components without using parent-child relationship?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Data can be shared using services, NgRx, or local storage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">43. What are Angular templates?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Templates are HTML that render the component. They can include Angular directives, bindings, and expressions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">44. What is Angular&#8217;s module injector?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The module injector is a dependency injection container that is responsible for creating services and injecting them into components.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">45. How do you define routes in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Routes are defined using the RouterModule and its forRoot() or forChild() methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">46. What is a router outlet in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A router outlet is a directive that acts as a placeholder for the routed component view.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">47. How do you handle HTTP errors in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: HTTP errors can be handled using the catchError operator from RxJS in the HttpClient call.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">48. What is the difference between an Observable and a Promise?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Observables are lazy and can emit multiple values over time, whereas Promises are eager and can only emit a single value once.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">49. What is the use of the async pipe in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: The async pipe automatically subscribes and unsubscribes from Observables or Promises, keeping the template clean and reducing boilerplate code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">50. How do you create a custom pipe in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: A custom pipe can be created using the @Pipe decorator and implementing the PipeTransform interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">51. How do you create a new Angular project?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use Angular CLI to create a new project by running the command <code>ng new project-name<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">52. How do you generate a new component using Angular CLI?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the command <code>ng generate component component-name<\/code> or <code>ng g c component-name<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">53. How do you add Angular Material to your project?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the command <code>ng add @angular\/material<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">54. How do you implement a service in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create a service using the CLI <code>ng generate service service-name<\/code> and then inject it into your components or other services.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">55. How do you fetch data from an API in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the HttpClient service to make HTTP requests. Inject HttpClient into your service and use methods like <code>get()<\/code>, <code>post()<\/code>, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">56. How do you handle HTTP errors in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>catchError<\/code> operator from RxJS to handle errors in HTTP calls.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">57. How do you implement routing in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Define routes in the <code>AppRoutingModule<\/code> and use the <code>RouterModule.forRoot(routes)<\/code> method to configure the router.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">58. How do you pass data to a child component?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>@Input()<\/code> decorator in the child component to receive data from the parent component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">59. How do you emit events from a child component to a parent component?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>@Output()<\/code> decorator along with an <code>EventEmitter<\/code> to emit events to the parent component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">60. How do you create a form using Reactive Forms?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Import <code>ReactiveFormsModule<\/code>, create a <code>FormGroup<\/code> and <code>FormControl<\/code> in the component, and bind the form controls to the template using <code>formGroup<\/code> and <code>formControlName<\/code> directives.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">61. How do you validate form inputs in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use Angular validators such as <code>Validators.required<\/code>, <code>Validators.minLength<\/code>, etc., and apply them to form controls in Reactive Forms or template-driven forms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">62. How do you implement lazy loading in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Configure lazy loading by using the <code>loadChildren<\/code> property in your route definitions and setting it to the path of the module you want to load lazily.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">63. How do you optimize an Angular application?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use lazy loading, AOT compilation, tree shaking, minification, and optimization tools like Angular CLI&#8217;s <code>ng build --prod<\/code> command.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">64. How do you create a custom directive?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the Angular CLI command <code>ng generate directive directive-name<\/code>, and implement your custom logic in the directive class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">65. How do you create a custom pipe?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the Angular CLI command <code>ng generate pipe pipe-name<\/code> and implement the <code>PipeTransform<\/code> interface in your pipe class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">66. How do you implement a guard to protect routes?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create a guard using the CLI <code>ng generate guard guard-name<\/code> and implement the <code>CanActivate<\/code> interface to control access to routes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">67. How do you perform unit testing of an Angular component?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Write test cases using Jasmine and Karma. Use <code>TestBed<\/code> to configure the testing module and <code>ComponentFixture<\/code> to access the component instance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">68. How do you inject a service into a component?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>constructor<\/code> of the component to inject the service by specifying it as a parameter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">69. How do you create and use a shared module?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create a shared module using <code>ng generate module shared<\/code>, declare and export common components, directives, and pipes, and import this module into other modules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">70. How do you handle route parameters?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>ActivatedRoute<\/code> service to access route parameters using the <code>paramMap<\/code> or <code>snapshot<\/code> property.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">71. How do you implement Angular animations?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Import <code>BrowserAnimationsModule<\/code>, define animations using Angular&#8217;s <code>trigger<\/code>, <code>state<\/code>, <code>style<\/code>, <code>transition<\/code>, and <code>animate<\/code> functions, and bind animations to HTML elements using <code>[@animationName]<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">72. How do you manage state in Angular using NgRx?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Install NgRx, create actions, reducers, selectors, and effects, and configure the store module in your application module.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">73. How do you unsubscribe from observables in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>unsubscribe()<\/code> method or the <code>takeUntil<\/code> operator from RxJS to manage subscriptions and prevent memory leaks.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">74. How do you use the Angular async pipe?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Bind the async pipe to an observable in the template to automatically subscribe and unsubscribe from the observable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">75. How do you prefetch data for a route using resolvers?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create a resolver service that implements the <code>Resolve<\/code> interface, fetch the required data, and configure the resolver in the route definition.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">76. How do you configure global error handling in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Implement a global error handler by creating a service that implements the <code>ErrorHandler<\/code> interface and provide it in the <code>providers<\/code> an array of your modules.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">77. How do you handle child routes?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Define child routes using the <code>children<\/code> property in your route configuration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">78. How do you set up Angular Environment configurations?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>src\/environments<\/code> folder to define different environment files like <code>environment.ts<\/code> and <code>environment.prod.ts<\/code>, and configure them in <code>angular.json<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">79. How do you use ViewChild and ContentChild in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use <code>@ViewChild<\/code> to access template elements and child components in the same template. Use <code>@ContentChild<\/code> to access projected content within a component.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">80. How do you implement a custom validator in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create a validator function or a directive that implements <code>Validator<\/code> interface, and use it in form controls.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">81. How do you manage HTTP interceptors?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create an HTTP interceptor by implementing the <code>HttpInterceptor<\/code> interface, and provide it in the <code>providers<\/code> an array of your module using the <code>HTTP_INTERCEPTORS<\/code> token.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">82. How do you configure internationalization (i18n) in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use Angular&#8217;s built-in i18n module, extract translatable strings using <code>ng xi18n<\/code>, and create locale-specific translation files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">83. How do you use Angular Schematics?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use Angular CLI commands to generate code templates and modify projects. You can create custom schematics for reusable code generation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">84. How do you implement nested forms in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Create nested <code>FormGroup<\/code> instances and bind them to form elements in the template using <code>formGroupName<\/code> directives.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">85. How do you use the Renderer2 service in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Inject the <code>Renderer2<\/code> service into your component or directive, and use its methods to manipulate the DOM in a safe and platform-independent manner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">86. How do you optimize Angular applications for mobile devices?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use responsive design techniques, lazy loading, tree shaking, and performance optimization tools like Lighthouse to optimize Angular applications for mobile devices.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">87. How do you create a custom Angular library?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the Angular CLI to create a new workspace and generate a library using <code>ng generate library library-name<\/code>. Develop and publish the library for reuse in other projects.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">88. How do you debug Angular applications?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use browser developer tools, Angular DevTools, and the <code>ng serve --source-map<\/code> option to debug Angular applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">89. How do you handle CORS issues in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Configure CORS on the server side or use a proxy in the Angular development environment by setting up the <code>proxy.conf.json<\/code> file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">90. How do you use Angular&#8217;s built-in pipes?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Apply built-in pipes like <code>DatePipe<\/code>, <code>CurrencyPipe<\/code>, <code>UpperCasePipe<\/code>, etc., directly in your templates using the pipe operator <code>|<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">91. How do you handle browser history in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the Angular Router to manage browser history and navigation. The <code>Location<\/code> service can also be used for more fine-grained control.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">92. How do you implement file upload in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>FormData<\/code> object along with <code>HttpClient<\/code> to send file data to the server. Create a file input element in your template to select files.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">93. How do you handle authentication and authorization in Angular?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Implement authentication using services like Firebase, OAuth, or custom backends, and protect routes using guards. Manage user roles and permissions to implement authorization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">94. How do you create a custom HTTP request header?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use the <code>HttpHeaders<\/code> class to create custom headers and attach them to your HTTP requests using the <code>HttpClient<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">95. How do you configure Angular application styles?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use global styles in <code>styles.css<\/code> or <code>styles.scss<\/code>, component-specific styles in <code>styleUrls<\/code>, and Angular&#8217;s <code>ViewEncapsulation<\/code> to encapsulate styles.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">96. How do you handle cross-component communication?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Use services to share data between components, event emitters, input\/output properties, or state management libraries like NgRx.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">97. How do you use the Angular CDK?<\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Import Angular CDK modules<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. What is Angular? Answer: Angular is a platform and framework for building single-page client applications using HTML and TypeScript. It is developed and maintained by Google. 2. What is TypeScript? Answer: TypeScript is a superset of JavaScript that adds static typing to the language. Angular applications are written in TypeScript. 3. What are Angular &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[14181],"tags":[],"class_list":["post-136367","post","type-post","status-publish","format-standard","","category-angular"],"jetpack_publicize_connections":[],"acf":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p99pkJ-ztt","_links":{"self":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/136367"}],"collection":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/comments?post=136367"}],"version-history":[{"count":2,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/136367\/revisions"}],"predecessor-version":[{"id":136370,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/posts\/136367\/revisions\/136370"}],"wp:attachment":[{"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/media?parent=136367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/categories?post=136367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sushilkumar.ind.in\/blog\/wp-json\/wp\/v2\/tags?post=136367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}