Pre Course Home Next

Angular Interview Questions Tutorial

Basic Angular (v2 to v7) Questions

Q 1. What is Angular?
A.
Angular is frontend development framework, based on JavaScript.

Q 2. What is current version of Angular?
A.
Angular 7 is the latest version of Angular. It’s a major release that implements a good number of new features, changes, and performance improvements.

Q 3. What is TypeScript?
A. TypeScript is a language developed by Microsoft, which compiles to JavaScript. So, it's superset of Javascript. TypeScript gives the ability to easly implement OOPs concepts, types, async/await, classes and many more features in Javascript.

Q 4. What are the advantages of Angular?
A.
Following are the some of the major advantages of Angular:

  • Two-way data bindings
  • MVC pattern
  • RESTful services supported
  • Dependency Injection
  • Mobile and test friendly

Q 5. What new features are added in Angular 7?
A.
In Angular 7, following new features are added:

  • Drag & Drop
  • Virtual scrolling
  • Angular material & component dev kit (CDK)
  • CLI prompts

Q 6. What are the building blocks of Angular?
A.
Following are the building blocks of Angular:

  • Components
  • Modules
  • Directive
  • Services
  • Routing
  • Dependency Injection
  • Template

Q 7. What is the difference between component and directive?
A.
Components make the smaller area of the webpage, while directive adds behavior on DOM element.

Q 8. What is Transpiling in Angular?
A.
Transpiling means converting one programming source code to another programming language source code. In Angular context, it means converting TypeScript code into JavaScript code.

Q 9. What is the sequence of Angular Lifecycle Hooks?
A.
Following is the order or Angular life cycle hooks:

  • OnChange
  • OnInit
  • DoCheck
  • AfterContentInit
  • AfterContentChecked
  • AfterViewInit
  • AfterViewChecked
  • OnDestroy

Q 10. If you have added a service in the providers section of 3 components, when those components will called, how many instance of that service will be created?
A.
For each component, one instance of the service will be created. So there will be total 3 instance of this service created.

Q 11. What is the difference between constructor and ngOnInit?
A.
Constructor is the part of TypeScript class, whereas, ngOnInit is Angular lifecycle hook. Whenever any instance of the class will be created, the first thing called will be constructor. So we use constructor for dependency injection. ngOnInit is used for apply logic when needs to be done when component is being initialized. Constructor will be executed before the ngOnInit.

Q 12. What are HTTP Interceptors?
A.
Http interceptors are used to add some common pre-request logic in the HTTP call from Angular application. A common scenario is adding JWT bearer token in the HTTP request.

Q 13. What's the difference between Observables and Promises?
A.
Observables are lazy. Means with observables, nothing will happen until there is subscribtion made. Once subscription is made, observables with update the client everytime there is some event. In this way observables allows passing multiple events from single subscription.

With promises, there is only one single event. As soon as promise is made, execution happens.

Q 14. What is dependency injection?
A.
When any module of peice of code depends on another module or code, then its said that modules have dependancy on other module. Angular have built-in dependency injection capability. Dependency injection menas resovling the dependency and creating the dependent object ar runtime.

 Q 15. How Angualr performs the dependency injection?
A.
In Angular we don't need to create instance of the class in constructor. We need to first add that dependency in the providers array of the parent module. Then just inject that class as paramenter in the class constructor.

Pre Course Home Next