Angular Interview Questions On Routing

Question: Can You Think of Any Disadvantages of Using Angular?

Answer: Not as a disadvantage, but in some scenarios, Angular may not be the right fit. For example, for short-term projects or light-weight websites that have more static content do not require a complex framework like Angular. Same way, apps that have a microservice design approach will find too many unused features if they use Angular since it is a complete solution. There is less flexibility with the developer to choose additional tools.

Question: What Is the Purpose of Angular?

Answer: The purpose of using Angular is to create fast, dynamic, and scalable web applications with ease, using components and directives.

What are directives in Angular?

A directive is a class in Angular that is declared with a @Directive decorator.

Every directive has its own behaviour and can be imported into various components of an application.

When to use a directive?

Consider an application, where multiple components need to have similar functionalities. The norm thing to do is by adding this functionality individually to every component but, this task is tedious to perform. In such a situation, one can create a directive having the required functionality and then, import the directive to components which require this functionality.

Types of directives:

1. Component directives

These form the main class in directives. Instead of @Directive decorator we use @Component decorator to declare these directives. These directives have a view, a stylesheet and a selector property.

2. Structural directives

  • These directives are generally used to manipulate DOM elements.
  • Every structural directive has a ‘ * ’ sign before them.
  • We can apply these directives to any DOM element.
  • Let’s see some built-in structural directives in action:

    In the above example, we can *ngIf and *ngFor directives being used.

    *ngIf is used to check a boolean value and if it’s truthy,the div element will be displayed.

    *ngFor is used to iterate over a list and display each item of the list.

    3. Attribute Directives

    These directives are used to change the look and behaviour of a DOM element. Let’s understand attribute directives by creating one:

    How to create a custom directive?

    We’re going to create an attribute directive:

    In the command terminal, navigate to the directory of the angular app and type the following command to generate a directive: ng g directive blueBackground

    The following directive will be generated. Manipulate the directive to look like this:

    Now we can apply the above directive to any DOM element:

    Hello World!

    Question: Is the Routing Module Mandatory for an Application?

    Answer: No, routing module can be totally skipped if there are simple configurations.

    Why Angular?

    Angular comes with a host of benefits and features that are apt for enterprise applications and websites that have a lot of dynamic content or multiple workflows. Whether it is exhaustive documentation, or the extensive support by Google, or component-based architecture (from version 2), Angular has all you can ask for from a web development framework. Some reasons why you should use Angular are –

  • Great support by Google, thus making the platform user-friendly and trustworthy.
  • A component-based architecture where the application is divided into functional and logical components that are independent of each other. Parts can be decoupled, replaced, or reused easily. This type of architecture also ensures easier testing at each stage.
  • A lot of reusable code and third-party components are available, thus improving productivity.
  • The code is rendered faster because it gets converted from TypeScript (or HTML) to JavaScript during the build process itself. This is called the Ahead-of-Time (AOT) compilation.
  • Command Line Interface (CLI) – CLI facilitates development in the most efficient way. You can create a new project, add your functionalities, and test them quickly. Further, initialization and configuration become easy too.
  • Angular six allows adding custom elements to web apps built with other environments like React, Vue, jQuery, etc.…
  • Angular six also included an Ivy renderer that translates components and templates into JavaScript by rendering. During the process, any unused code is removed, thus making web apps load faster.
  • Angular Universal that is used for server-side rendering, helps increase the number of users on the website and faster loading of pages.
  • Excellent documentation and support community
  • Most Important Angular Routing Interview Questions

    Related Posts

    Leave a Reply

    Your email address will not be published. Required fields are marked *