Angular Interview
Angular Interview
AngularJS Angular
Based on the MVC design pattern Based on components, modules, and directives
Can’t build SEO friendly applications SEO friendly applications can be easily created
Requires specific ng directive for each For event binding, () is used and for image or propert
of property, event, and image binding [] is used
1
ng new <appname> [options]
2
to create a class using CLI (in Angular 7), we have to type –
3
ng generate class MySampleClass [options]
4
to generate a component,
5
ng g c <componentname>
12. Question: How Are Angular Expressions Different From Javascript Expressions?
Answer: Both are similar and can have operators, variables, and literals. However, some differences
between both are –
Expressions are evaluated against a scope Expressions are evaluated against the global
object window
You can mention any 3-4 to the examiner. If they specifically ask, you can say that particular point of
difference.
Component Directive
The primary purpose of ingredients is to break the Purpose of the `directive is to cre
complex application into smaller, more manageable parts new custom components that are
(components) reusable
16. Question: What Is Data Binding, and What Are the Different Categories of Data Binding?
Answer: Data binding is used to connect the application data and DOM i.e. components with the
template. They can be categorized based on the direction of the data flow.
Data flow
Type Description
Direction
Interpolation -
From source to Interpolates values calculated from applic
Attribute, style, class,
view (one-way) data into HTML
property
From lightview to
Enables applications to respond to users
the source (one- Event
target environment
way)
17. Question: Explain the Differences Between One-Way Binding and Two-Way Binding
Answer:
Filter
Description
name
Limits array into the specified number of elements; string to specified number of
limitTo
characters
JS modules NgModules
Cant extend the entire The entire application can be extended with services using
application with services @NgModules.providers list to add providers
Can import or export any kind It can import or export only those declarable classes that it o
of classes imports from other modules.
20. Question: What Are ngIf and ngFor? Can You Show a Small Example to Use Them?
Answer:
Just like if and for in other languages, ngIf and ngFor are used as control statements. Example –
<p *ngIf="display">Show this only if the Boolean "display" is true</p>
Where the display is a boolean with the value true or false. Learn more about ngIf.
ngFor is used to loop through and display elements of an array (set of data).
<tr *ngFor="let student of students; let i = index"> <td>{{student.name}}
</td> <td>{{i}}</td> </tr>
The second part (i=index) is optional and only needed if you want to display the index.
21. Question: Which Is the Latest Version of Angular? What Are the New Features in It?
Answer: The latest version is Angular 8. Some features are –
Support for TypeScript 3.4.
Dynamic import for lazy routes.
Web workers.
Differential loading for application code.
Introduction of Angular Ivy – improved payload size, backward compatibility, faster re-build time,
easier debugging etc…
22. Question: What Is a Component?
Answer: The component is a logical piece of code. The component consists of the template (that
contains the HTML (or URL) that needs to be rendered), class (class that defines properties and
methods that supports the view) and metadata (defined using decorator).
Example –
@Component ({ selector: 'my-app', template: ` <div> <h1>{{appTitle}}</h1>
<div>What is your name?</div> </div>, })
23. Question: Is There a Way to Convert the Typescript Code Into Javascript Code? How Is It Done?
Answer:
Yes, converting TypeScript into JavaScript is called as transpilation.
26. Question: Can You Create a Parameterized Pipe in the Above Example?
Answer:
Yes,
<p>Price is {{ price | currency : “USD$” : 0.00 }}</p>
29. Question: What Is the Difference Between Pure and Impure Pipe?
Answer:
Doesn’t get affected by internal Can produce different output for the same input based
state internal state
Can be shared with many different It cannot be shared because the internal state can be a
instances by any factors.
ngOnChanges This method is called when the value of a data-bound property chan
This method is for detecting and taking action on changes that Angu
ngDoCheck
won't detect on its own.
1
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; After this,
import the required animation functions into the component files. Example, import { state, animate,
transition, // ... } from '@angular/animations';
Next, add the animation metadata property within the @Component() decorator in the component
file.
Plain Text
1
@Component({ selector: 'app-root', templateUrl: 'app.component.html', animations: [ // animation
triggers go here ] })
38. Question: How Can You Disable All the Animations in Angular?
Answer:
To disable all the animations, place the @.disabled host binding on the topmost Angular component.
Explain the steps to create a reusable animation.
To create an animation that can be reused, use the animation() method and define the animation in a
separate .ts file. Declare this animation as a const export variable. This can be then imported and
reused in any app components that use the useAnimation() API. Check an example on the Angular
website.
39. Question: Mention Some of the Functions That Help Control Complex Animation Sequences
Answer:
finds one or more inner HTML elements within the current element being animat
query()
the sequence
sequence(
runs animation steps one after another (sequentially)
)
40. Question: Explain the Features of Forms in Angular.
Answer:
There are two approaches to handle form data (user inputs) – reactive and template-driven.
Reactive forms can be used when you are using reactive patterns in your application and forms are a
key part of your application. These forms are scalable, robust and testable.
Template-driven forms are used to add simple forms, for example, a sign-up page. These are not as
scalable as reactive forms and should be used only if your form requirements are simple and minimal.
43. Question: Explain the Difference Between Annotations and Decorators in Angular
Answer:
Annotations are hardcoded features of Angular and store array in it. The compiler creates am
attribute of the annotated class and instantiates an object of the same name, passing the metadata to
the constructor.
Decorators, on the other hand, are functions that receive the object to be decorated. After receiving,
they are free to modify the object in the way it likes. Decorators are implemented by the TypeScript
compiler.
44. Question: What Is the Difference Between Class Decorators and Class Field Decorators?
Answer: Class decorators appear just before class definition, whereas class field decorators appear
just before a field in the class definition. Examples of class decorators are @Component, @NgModule
etc… Examples of a class field decorator are @Input, @Output etc…
49. Question: Talk About Some Differences Between Promise and Observable
Answer:
Promise Observable
Used with .then() clause Has chaining and subscription to handle complex applica
Errors are pushed to child Centralized and predictable error handling by the use of
promises subscribe() method
Provides only one value Can provide multiple values over time
50. Question: What Is the Single Page Application? How Is It Different From Traditional Web
Technology?
Answer: In a single page application (SPA), only the home page (index.html) is maintained throughout
even though the URL keeps on changing. It is faster and easier to implement when compared with
traditional web technology. In traditional technology, every time a user makes a request, the request
is passed on to the server. This takes more time.
52. Question: List the Differences Between Just-In-Time (JIT) Compilation and Ahead-Of-Time (AOT)
Compilation
Answer:
With JIT, the compilation happens during run-time in the browser. It is the default way used by
Angular. The commands used for JIT compilation are –
ng build ng serve
In AOT compilation, the compiler compiles the code during the build itself. The CLI command for aot
compilation is -
ng build --aot ng server –aot
AOT is more suitable for the production environment whereas JIT is much suited for local
development.
54. Question: Discuss Some Differences Between Angular and Jquery. Which One Is Most Suitable for a
Complex Website With Many Workflows?
Answer:
Angular jQuery
Front end framework based on TypeScript and JS library that supports animation and DOM
JavaScript manipulation
For a complex website with multiple workflows, Angular is more suitable and easier to develop and
maintain.
55. Question: What Is an Angular Library? Can You Create Your Own Library in Angular?
Answer:
Angular library is a set of generic solutions that other developers have put together to be re-used. We
can create own library using Angular. These libraries can be published and shared as npm packages. A
library should be imported in the app.