Top 10 Interview Questions and Answers on Angular 2020


 Angular Interview Questions and Answers

Q1. Name the building blocks of Angular.

 The Angular application is made using the following: 
·         Modules
·         Component
·         Template
·         Directives
·         Data Binding
·         Services
·         Dependency Injection
·         Routing

Q2. What is View Encapsulation?


View Encapsulation decides whether the styles defined in a component can affect the entire application or not. There are three ways to do this in Angular: 
Emulated: styles from other HTML spread to the component.
Native: styles from other HTML do not spread to the component.
None: styles defined in a component are visible to all components.

Q3. What are Services in Angular and what command is used to create a service?


Services help us in not repeating the code. With the creation of services, we can use the same code from different components. Here is the command to create a service in angular, ng g service User (a UserService is created when this command is used). 

 

Q4. Explain the usage of {{}}?

 

The set of brackets {{}} when used with an HTML tag, represent data from a component. For example, on a HTML page which has <h1>{{variableName}}</h1>, here the ‘variableName’ is actually typescript (component) data representing its value on the template; i.e., HTML. This entire concept is called String Interpolation. 


Q5. How is SPA (Single Page Application) technology different from the traditional web technology? 


In traditional web technology, the client requests for a web page (HTML/JSP/asp) and the server sends the resource (or HTML page), and the client again requests for another page and the server responds with another resource. The problem here is a lot of time is consumed in the requesting/responding or due to a lot of reloading. Whereas, in the SPA technology, we maintain only one page (index.HTML) even though the URL keeps on changing. 


Q6. Differentiate between Observables and Promises.

Observables are lazy, which means nothing happens until a subscription is made. Whereas Promises are eager; which means as soon as a promise is created, the execution takes place. Observable is a stream in which passing of zero or more events is possible and the callback is called for each event. Whereas, promise handles a single event. 


Q7. What is an AsyncPipe in Angular? 

When an observable or promise returns something, we use a temporary property to hold the content. Later, we bind the same content to the template. With the usage of AsyncPipe, the promise or observable can be directly used in a template and a temporary property is not required. 


Q8. Explain Authentication and Authorization.

Authentication: The user login credentials are passed to an authenticate API (on the server). On the server side validation of the credentials happens and a JSON Web Token (JWT) is returned. JWT is a JSON object that has some information or attributes about the current user.  Once the JWT is given to the client, the client or the user will be identified with that JWT.
Authorization: After logging in successfully, the authenticated or genuine user does not have access to everything. The user is not authorized to access someone else’s data,  he/she is authorized to access some data.  


Q9. What is AOT Compilation?

Every angular application gets compiled internally. The angular compiler takes javascript code, compiles it and produces javascript code again. Ahead-of-Time Compilation does not happen every time or for every user, as is the case with Just-In-Time (JIT) Compilation. 


Q10. What is Redux? 

It is a library which helps us maintain the state of the application. Redux is not required in applications that are simple with the simple data flow, it is used in Single Page Applications




Post a Comment

0 Comments