Interview Questions Related to Angular


Q6: What are directives in Angular?

Ans: The primary feature of Angular is the directives. They give you the opportunity to write new HTML syntax according to your application. In actuality, they are functions that work when the Angular compiler is able to find them in the DOM. The Angular directives can be divided into three important parts: Component Directives, Structural Directives, and Attribute directives.

  • Component Directives: they are simply directives that have templates. By using the directive API, they provide a neat way to define them. In contrast to it, the other ones lack templates. Rather than that, they manipulate the DOM.
  • Structural Directives: These are designed to make and destruct DOM elements.
  • Attribute Directives: they change the behavior and the way the DOM looks. As a result, it is manipulated. They are used when we need to display or conceal, and the application of a conditional style to the elements

Q7: Explain data binding?

Ans: In the Angular framework, the feature that has the most significance and is considered to be very powerful is data binding. It aids in defining the communication between the Document Object Model and the component. It provides ease in the process that defines interactive applications. The best part is that there is no need of pushing and pulling data between the template and component. Mainly, data binding in angular has four types that are equally important for performing different actions: String Interpolation, Property Binding (aids in setting values for properties of HTML elements), Event Binding (handles events), and the Two-Way Data Binding( combines both property and event binding).

Q8: What is the aim of a filter in Angular?

Ans: Filters can be used to allow the formatting of the value of an expression. In angular, due to this process, data can be displayed to the user. When using angular, you can add these filters to the templates, directives, controllers, or services. Apart from that, it helps you generate your own custom filters. When you use them, you are allowed to organize data in a certain way. And, only if it meets specific criteria, the data is displayed. To add these filters to the expression, you must use a pipe character | after using the filter.

Q9: What is the meaning of Dependency Injection in Angular?

Ans: In angular, the term Dependency Injection (DI) is used for a software design pattern. Here, the objects are transferred as dependencies instead of hard-coding them within the component. The phenomenon of Dependency Injection is very helpful for the user, especially, when they want to detach the logic of object creation from that of its consumption. The DI must be configured in advance. The ‘config’ operation uses the DI while the loading of the module takes place to restore the elements of the application. If you desire to change dependencies according to your requirements, this feature is brilliant.

Q10: What are the similarities and dissimilarities between Angular expressions and JavaScript expressions?

Ans: Angular expressions and JavaScript expressions resemble each other in some ways. However, there are dissimilarities between them that show that they are not alike. First of all, let’s talk about the factor that is the same in both of them. Both Angular Expression and JS expressions contain literals, operators, and variables. That’s it, this is the only common thing that is present in them. Now, we will move onto the dissimilarities.

  • It is possible to write them inside the HTML tags. On the other hand, you can’t write JS expressions inside the HTML tags.
  • Angular expressions can’t support loops, exceptions, and conditionals. On the flip side, JS expressions support all of them.
  • Filters are supported by Angular expressions, but JavaScript Expressions do not support filters.