Angular Interview Questions Series 1

Angular Interview Questions Series 1

Angular Interview Questions Series 1

1. What is Angular? Why was it introduced?

Angular was introduced to create Single Page applications. This framework brings structure and consistency to web applications and provides excellent scalability and maintainability. 

Angular is an open-source, JavaScript framework wholly written in TypeScript. It uses HTML's syntax to express your application's components clearly. 


2. What is TypeScript?

TypeScript is a superset of JavaScript that offers excellent consistency. It is highly recommended, as it provides some syntactic sugar and makes the code base more comfortable to understand and maintain. Ultimately, TypeScript code compiles down to JavaScript that can run efficiently in any environment. 


3. What is data binding? Which type of data binding does Angular deploy?

Data binding is a phenomenon that allows any internet user to manipulate Web page elements using a Web browser. It uses dynamic HTML and does not require complex scripting or programming. We use data binding in web pages that contain interactive components such as forms, calculators, tutorials, and games. Incremental display of a webpage makes data binding convenient when pages have an enormous amount of data. 

Angular uses the two-way binding. Any changes made to the user interface are reflected in the corresponding model state. Conversely, any changes in the model state are reflected in the UI state. This allows the framework to connect the DOM to the Model data via the controller. However, this approach affects performance since every change in the DOM has to be tracked.


4. What are Single Page Applications (SPA)?

Single-page applications are web applications that load once with new features just being mere additions to the user interface. It does not load new HTML pages to display the new page's content, instead generated dynamically. This is made possible through JavaScript's ability to manipulate the DOM elements on the existing page itself. A SPA approach is faster, thus providing a seamless user experience. 


5. What are decorators in Angular? 

Decorators are a design pattern or functions that define how Angular features work. They are used to make prior modifications to a class, service, or filter. Angular supports four types of decorators, they are:

  1. Class Decorators
  2. Property Decorators
  3. Method Decorators
  4. Parameter Decorators


6. Mention some advantages of Angular.

Some of the common advantages of Angular are - 

  1. MVC architecture - Angular is a full-fledged MVC framework. It provides a firm opinion on how the application should be structured. It also offers bi-directional data flow and updates the real DOM. 
  2. Modules: Angular consists of different design patterns like components, directives, pipes, and services, which help in the smooth creation of applications.
  3. Dependency injection: Components dependent on other components can be easily worked around using this feature. 
  4. Other generic advantages include clean and maintainable code, unit testing, reusable components, data binding, and excellent responsive experience.


7. What are Directives in Angular?

Directives are attributes that allow the user to write new HTML syntax specific to their applications. They execute whenever the Angular compiler finds them in the DOM. Angular supports three types of directives.  

  1. Component Directives
  2. Structural Directives
  3. Attribute Directives 


8. What is an AOT compilation? What are its advantages?

The Ahead-of-time (AOT) compiler converts the Angular HTML and TypeScript code into JavaScript code during the build phase, i.e., before the browser downloads and runs the code.

Some of its advantages are as follows. 

  1. Faster rendering
  2. Fewer asynchronous requests
  3. Smaller Angular framework download size
  4. Quick detection of template errors
  5. Better security


9. What are Pipes in Angular? 

angular pipes

Pipes are simple functions designed to accept an input value, process, and return as an output, a transformed value in a more technical understanding. Angular supports several built-in pipes. However, you can also create custom pipes that cater to your needs. 

Some key features include: 

  1. Pipes are defined using the pipe “|” symbol. 
  2. Pipes can be chained with other pipes.
  3. Pipes can be provided with arguments by using the colon (:) sign.


10. Explain the lifecycle hooks in Angular

In Angular, every component has a lifecycle. Angular creates and renders these components and also destroys them before removing them from the DOM. This is achieved with the help of lifecycle hooks. Here's the list of them - 

  1. ngOnChanges() - Responds when Angular sets/resets data-bound input properties.
  2. ngOnInit() - Initialize the directive/component after Angular first displays the data-bound properties and sets the directive/component's input properties/
  3. ngDoCheck() - Detect and act upon changes that Angular can't or won't detect on its own.
  4. ngAfterContentInit() - Responds after Angular projects external content into the component's view.
  5. ngAfterContentChecked() - Respond after Angular checks the content projected into the component.
  6. ngAfterViewInit() - Respond after Angular initializes the component's views and child views.
  7. ngAfterViewChecked() - Respond after Angular checks the component's views and child views.
  8. ngOnDestroy - Cleanup just before Angular destroys the directive/component.



Share Article:
  • Facebook
  • Instagram
  • LinkedIn
  • Twitter
  • Recent Posts