Angular Questions & Answer
https://www.code-sample.com/2018/05/angular-5-6-httpclient-requests-and.html
0.What is the difference between synchronous vs asynchronous and blocking vs non-blocking?
synchronous
Synchronous simply means that things follow in order. You do step 1, then you do step 2, then you do step 3. Step 3 never occurrs before step 2 in this synchronous process. Step 2 must conclude before you start step 3.
asynchronous
Asynchronous (not synchronous) means that the steps in the process may occur at the
same time, out of order, or at least before other steps complete.
1.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).
2 .What is Dependency Injection in Angular 4?
When a component is dependent on another component the dependency is injected/provided during runtime.
3. In how many ways the Data Binding can be done?
Data Binding happens between the HTML (template) and typescript (component). Data binding can be done in 3 ways:
(i) Property Binding (ii) Event Binding (iii) Two-Way Data Binding.
4. What is the sequence of Angular Lifecycle Hooks?
OnChange() - OnInit() - DoCheck() - AfterContentInit() - AfterContentChecked() - AfterViewInit() - AfterViewChecked() - OnDestroy().
5.Differentiate between Observables and Promises.
5.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.
6.What is Components
Technically components are basically TypeScript classes that interact with the HTML files of the components, which get displayed on the browsers.
What Are Angular Directives?
Angular Directive is a TypeScript class which is declared as a @directive decorator.
The directives allow you to attach behavior to DOM elements and the @directive decorator provide you an additional metadata that determines how directives should be processed, instantiated, and used at run-time.
What Are decorators?
The Decorators are functions that modify JavaScript classes and it also used for attaching metadata to classes.
What Is the Angular Compiler?
25) What is the use of the ‘this’ keyword?
The Angular compiler converts our applications code (HTML and TypeScript) intoJavaScript code before browser downloads and runs that code.
The @NgModule metadata plays an important role in guiding the compilation process and also tells the compiler what components to compile for this module and how to link this module with other modules.
The Angular offers two ways to compile our application code-
1. Just-in-Time (JIT) - JIT compiles our app in the browser at runtime (compiles before running).
2. Ahead-of-Time (AOT) - AOT compiles our app at build-time (compiles while running).
The JIT compilation is the default when we run the build or serve CLI commands -
ng build
ng serve
The AOT compilation, we append the --aot flags to build or serve CLI commands -
ng build --aot
ng serve --aot
Why we need Compilation in Angular?
We need compilation for achieving a higher level of efficiency, performance improvements, faster rendering and also sometimes detect template errors earlier in our Angular applications.
Why Compile with AOT?
1. Faster Rendering
2. Asynchronous Requests
3. Detect template errors earlier
4. Smaller Angular frameworks download size
What Is Dependency Injection (DI)?
Dependency Injection is a powerful pattern for managing code dependencies. DI is a way to create objects that depend upon other objects.
the new HttpClient service is included in the HTTP Client Module that used to initiate HTTP request and responses in angular apps. The HttpClientModule is a replacement of HttpModule
Benefits of HttpClient -
Benefits of HttpClient -
1. HttpClient include the testability features
2. HttpClient include typed request
3. HttpClient include response objects
4. HttpClient include request and response interception
5. HttpClient include Observable APIs
6. HttpClient include error handling
25) What is the use of the ‘this’ keyword?
The keyword ‘this’ refers to the current instance of the object when used inside a function. But, when used outside a function, it refers to
the window object.
the window object.
23) Explain the terms synchronous and asynchronous code.
The synchronous code is something that should be finished before anything else can happen, or in other words, the synchronous code is blocking. And the Asynchronous code is something in which actions can happen and is not dependent on other actions- in other words, it is non-blocking.
Comments
Post a Comment