Angular Interview Questions Part 5

 1. What are three different types of directives and explain them with example?

Three different types of directives in angular are :

    i. Component directive : It is a directive with a template, example : @Component

    ii. Attribute directive: It changes the behavior and appearance of the element, example: ngModel

    iii. structural directive: directive that changes DOM layout by adding and removing DOM elements.


2. What is Refactoring?

   Refactoring is the process of changing the name of any file or folder and reflect that change all over the project structure.


3. Explain ng generate?

ng generate command is the angular cli command that is used to generate components, services, modules, etc automatically. 

syntax: ng generate component component-name or ng g c component-name



4. What is Dependency injection?

Before understanding the dependency injection we need to understand what dependency means in programming;  When class A uses the functionality of class B then it is fair enough to say that class A has dependency of class B.

But before using the functionality of another class object of that class needs to be created(i.e. class A has the instance of class B)

So transferring the task of creating the instance to someone else and directly using the dependency is called dependency injection.


5. How to navigate from within the component code?

We can navigate from the component code as;



6. What is a constructor in a class?

Constructor is a special type of  method that has no return type and has the same name as the name of the class. but in case of TypeScript only constructor() keyword is used to create a constructor. Constructor instantiate the object of the class i.e. the first thing that gets executed in a TypeScript class is the code inside constructor.


7. What is the syntax for ngFor Loop?

ngFor is a structural directive that has the ability of changing the  DOM layout by adding and removing DOM element.

syntax: 




Video Tutorial: