Angular Interviewquestions
Angular Interviewquestions
Ans : Data binding in AngularJS is the synchronization between the model and the
view. When data in the model changes, the view reflects the change, and when data
in the view changes, the model is updated as well.
Property Binding []
Event Binding ()
[()] - ngmodel
3.Content Projection
Ans - It is good for reusability
Content projection is a pattern in which you insert, or project, the content you
want to use inside another component. For example, you could have a Card component
that accepts content provided by another component.
following content can be insert
Inner HTML
HTML Elements
Styled HTML
Another Component
To insert HTML elements or other components in a component, you need to use
content projection
ngOnInit Constructor
One of the Angular life cycle hook method Typescript feature
nothing to do with Angular
ngOnInit being added to prototype of the class created constructor is
transformed to function with the same name as class created
Called by Angular Called by Javascript
Engine
Invoked by Angular when component is initialized Constructor is
automaticlly called at the time of creating object of the class
Actual business logic performed here Used for Injecting
dependencies
Everything is ready at the time of invocation Not everything in
component is initialized at the time of invocation
10. Difference between form builder and form control and form group(Form-Array)
In Angular, a reactive form is a FormGroup that is made up of FormControls.
The FormBuilder is the class that is used to create both FormGroups and
FormControls
form controls are classes that can hold both the data values and the validation
information of any form element
The AOT (ahead-of-time) compiler in Angular converts Angular HTML and TypeScript
code into JavaScript code during the build phase, which makes the rendering process
much faster. This compilation process is needed since Angular uses TypeScript and
HTML code. The compiler converts the code into JavaScript, which can then be
effectively used by the browser that runs our application.
Fast rendering: Since, after compilation, the browser would download a pre-compiled
version of our application, it can render the application immediately without
compiling the app.
Less asynchronous requests: It takes external HTML templates and CSS style sheets
and inlines them within the application JavaScript, which reduces the number of
separate Ajax requests.
Smaller download size: The compiler will minify the code for us so that the
download size is less.
Template error detection: During the compilation phase, any issues in the templates
will be detected and reported by the compiler so that they can be corrected before
production.
15 modules in angular
Module in Angular refers to a place where you can group the components,
directives, pipes, and services, which are related to the application. In case you
are developing a website, the header, footer, left, center and the right section
become part of
a module. To define module, we can use the NgModule.
16 What is DOM
The full form of DOM is Document Object Model, and it is responsible for
representing the content of a web page and changes in the architecture of an
application. Here, all the objects are organized in the form of a tree, and the
document can easily be modified, manipulated, and accessed only with the help of
APIs
17. Template
18. Pipes in angular https://www.dotnettricks.com/learn/angular/pipes-custom-
pipes-example-usages
Pipes are simple functions that accept an input value and transform it based on
the developer's needs. There are predefined and user-defined pipes, they can be
accessed using the pipe symbol "|",
they can be chained together
Use your pipe in the HTML using ‘|’, which represents a pipe.
Pure pipe
Impure pipe
The pipe is executed only when it detects a change in primitive value or object
reference The pipe is executed on every change detection cycle irrespective of
the change in the input value.
A single instance is created.
The AsyncPipe allows you to bind your HTML templates directly to values that arrive
asynchronously manner that is a great ability for the promises and observables.
22. Difference between observable and promise
Observables Promises
Emit multiple values over a period of time.
Emit a single value at a time.
Are lazy: they’re not executed until we subscribe to them using the subscribe()
method. Are not lazy: execute immediately after
creation.
Have subscriptions that are cancellable using the unsubscribe() method, which stops
the listener from receiving further values. Are not cancellable.
Provide the map for forEach, filter, reduce, retry, and retryWhen operators. Don’t
provide any operations.
24 What is angular ?
27 What is TypeScript?
TypeScript is a typed superset of JavaScript created by Microsoft that adds
optional types, classes, async/await, and many other features, and compiles to
plain JavaScript. Angular built entirely in TypeScript and used as a primary
language. You can install it globally as
npm install -g typescript
28 Angular architecture
29.What are the key components of Angular?
Angular has the below key components,
Component: These are the basic building blocks of angular application to control
HTML views.
Modules: An angular module is set of angular basic building blocks like component,
directives, services etc. An application is divided into logical pieces and each
piece of code is called as "module" which perform a single task.
Templates: This represent the views of an Angular application.
Services: It is used to create components which can be shared across the entire
application.
Metadata: This can be used to add more data to an Angular class.
forRoot creates a module that contains all the directives, the given routes, and
the router service itself. forChild creates a module that contains all the
directives and the given routes, but does not include the router service.
It registers the routers and uses the router service created at the root level.
angular.json is related to angular ecosystem, its responsible for your angular app
configuration. You can learn more from official angular docs.
https://angular.io/guide/workspace-config
36. Doctype in html
37. session storage, local storage, cookies
38.15. What is the difference between absolute, relative, fixed, and static
positions?
Absolute - An absolute element is positioned relative to the nearest parent
element. In case a parent element is not present it is positioned based on the page
itself and moves along with the page scroll.
Relative - When an object is positioned relative to an element without adding any
position attributes nothing happens. However, if a positional attribute is placed
Eg: 20px to the right, the element will move 20px to the right of the original
element.
Fixed - A fixed position implies that the element remains fixed to the viewport,
which means it stays in the same place even if the page is scrolled.
Static - Elements are positioned static by default, these elements are not affected
by positional attributes (Top, bottom, left, right).
If an element is positioned static it follows the normal flow of the page.
40. Rx js operators
41. Subject
42. template driven and reactive forms
43. Lazy loading