Search Tutorials

Top Angular 2 Interview Questions and Answers | JavaInUse

Angular2 Interview Questions.

In this post we will look at Angular2 questions. Examples are provided with explanation.

Q: What are the new features of Angular2?
    A: Angular 2 is written entirely in Typescript and meets the ECMAScript 6 specification.
  • Component-Based- Angular 2 is entirely component based. Controllers and $scope are no longer used. They have been replaced by components and directives.
  • Directives- The specification for directives is considerably simplified, although they are still subject to change. With the @Directive annotation, a directive can be declared.
  • Dependency Injection- Because of the improved dependency injection model in Angular2 there are more opportunities for component / object-based work.
  • Use of TypeScript-TypeScript is a typed super set of JavaScript which has been built and maintained by Microsoft and chosen by the AngularJS team for development. The presence of types makes the code written in TypeScript less prone to run-time errors. In recent times, the support for ES6 has been greatly improved and a few features from ES7 have been added as well.
  • Generics- TypeScript has generics which can be used in the frontend.
  • Lambdas with TypeScript- In TypeScript, lambdas are available.
  • Forms and Validations- Forms and validations are an important aspect of frontend development. Within Angular 2 the Form Builder and Control Group are defined.
Q: What is the need of Angular2?
Angular 2 is not just a typical upgrade but a totally new development. The whole framework is rewritten from the ground. Angular 2 got rid of many things like $scope, controllers, DDO, jqLite, angular.module etc. It uses components for almost everything. Imagine that even the whole app is now a component. Also it takes advantage of ES6 / TypeScript syntax. Developing Angular 2 apps in TypeScript has made it even more powerful. . Apart from that, many things have evolved and re-designed like the template engine and many more.

Q: What is TypeScript ? What is the need for it in Angular2
TypeScript is a typed super set of JavaScript which has been built and maintained by Microsoft and chosen by the AngularJS team for development.
Understanding the need for TypeScript file in Angular2 applications

Q: What is ECMA Script ?
ECMAScript is a subset of JavaScript. JavaScript is basically ECMAScript at its core but builds upon it. Languages such as ActionScript, JavaScript, JScript all use ECMAScript as its core. As a comparison, AS/JS/JScript are 3 different cars, but they all use the same engine... each of their exteriors is different though, and there have been several modifications done to each to make it unique. Angular2 supports ES6 and higher versions.

Q: What is @NgModule?
@NgModule is a decorator function. A decorator function allows users to mark something as Angular 2 thing (could be a module or component or something else) and it enables you to provide additional data that determines how this Angular 2 thing will be processed, instantiated and used at the runtime. So, whenever user writes @NgModule, it tells the Angular 2 module, what’s going to be included and used in and using this module.
Example using @NgModule
Q: Which components are used to configure routing in Angular 2?
There are three main components that we use to configure routing in Angular 2-
  • Routes describes the application a€™s routes
  • RouterOutlet is a placeholder€ component that gets expanded to each route’s content
  • RouterLink is used to link to routes

Q: How to perform CRUD operations using Spring Boot and Angular?
We can develop a full stack application with angular as the frontend and the backend as Spring Boot.
Angular 7 + Spring Boot Application CRUD Example

Q: What is Basic Authentication? How to implement it using Angular?
Basic authentication is a simple authentication scheme built using the HTTP protocol. When using this protocol the HTTP requests have Authorization header which has the word Basic followed by a space and base 64 encoded string username:password.
Angular 7 + Spring Boot Application Basic Authentication Example

Q: What is Traceur compiler ?
Traceur is a compiler that allows you to use features from the future today. Traceur supports ES6 as well as some experimental features. Traceur's goal is to inform the design of new JavaScript features which are only valuable if they allow you to write better code.

Q: Why are decorators used in Angular 2 ?
In Angular 2, decorators allow developers to configure classes as particular elements by setting metadata on them. The most commons are the @Component one, for components and the @Injectable one, for classes you want to inject dependencies in.
Advanatges of using decorators are-
  • Separation of concerns.
  • Easy for tools to provide all kinds of support in templates like- error checking, auto-completion, graphical GUI designers
  • Support multiple modifications

Q: What are pipes in Angular 2 ?
Pipes in Angular 2 are a way to transform and format data right from your templates Out of the box you get pipes for dates, currency, percentage and character cases, but you can also easily define custom pipes of your own. Here for example we create a pipe that takes a string and reverses the order

Q: How can we achieve Internationalization using Angular 2 ?
It can be achieved using the directive i18n. Internationalization (or i18n, which stands for i--n) is the process of adapting software and web applications to multiple languages, allowing their application to be used by multiple language-speaking users. By ensuring that your application supports multiple languages, you can reach a broader audience and ensure a smooth user experience for multilingual users.
Q: What is component in Angular 2 ?
In angular, a Component is a special kind of directive that uses a simpler configuration which is suitable for a component-based application structure.

Q: What is @Inputs in Angular 2? ?
@Input allows you to pass data into your controller and templates through html and defining custom properties. This allows you to easily reuse components and have them display different values for each instance of the renderer.

Q: What is @Outputs in angular?
Components push out events using a combination of an @Output and an EventEmitter. This allows a clean separation between reusable Components and application logic.

Q: What are differences between Components and Directives?
Components Directives
For register component we use @Component meta-data annotation. For register directives we use @Directive meta-data annotation.
Component is a directive which use shadow DOM to create encapsulate visual behavior called components. Components are typically used to create UI widgets. Directives is used to add behavior to an existing DOM element.
Component is used to break up the application into smaller components. Directive is use to design re-usable components.
Only one component can be present per DOM element. Many directive can be used in a per DOM element.
@View decorator or templateurl template are mandatory in the component. Directive don’t have View.

Q: What is Angular 4? Have you used Angular 4?
angular4 Tutorials

Q: What is primeng? How can it be used with Angular2?
PrimeNG is a collection of rich UI components for Angular 2. PrimeNG is a sibling of the popular JavaServer Faces Component Suite, PrimeFaces. All widgets are open source and free to use under Apache License 2.0, a commercial friendly license. PrimeNG is developed by PrimeTek Informatics, a company with years of expertise in developing open source UI components. AngularJS makes it possible to use predefined components for development like tables etc. This helps developers save time and efforts. Using PrimeNG developers can create awesome applications in no time
PrimeNG-UI Components for AngularJS 2 Basic Example

Q: How to implement Datagrid Table with Angular 2 and PrimeNG ?
Angular2 PrimeNG Tutorial- Create a Hello World application using DataTable Grid

Q: Which other PrimeNG components have you used with Angular 2?
Create a simple PrimeNG application using PrimeNG Components like PrimeNG Button, Confirmation Box, Text Box.

Angular 4 Interview Questions

See Also

Spring Boot Interview Questions Apache Camel Interview Questions Drools Interview Questions Java 8 Interview Questions Enterprise Service Bus- ESB Interview Questions. JBoss Fuse Interview Questions Top ElasticSearch frequently asked interview questions