Angular Interview

 Angular

Start angular

Step -1 - Call main.ts - function called -> platformBrowserDynamic().bootstrapModule(AppModule) -> bootstrapModule will call module appModule

What is Metadata?

tell what type of classes e.g @NgModule, @component

What is decorator?

@NgModule, @component is decorator 

metadata privided through decorator

what is root module ?

setup execution environment

look for app component

create instance of component and insert in element

Parts of module?

- declaration

- imports

- export

- providers

- bootstrap

What is Directive 

whatever angular code we writes in html known as dirctives

    directives are used to modify dom or html element.

directives are three types (SAC)

1. structural - change structure of dom ,  ngFor, ngIf

2. Attribute - change behaviour of dom

3. Component Directive - when u creates any component, rwsuable component

- Built-in attribute directives

NgClass—adds and removes a set of CSS classes.

NgStyle—adds and removes a set of HTML styles.

NgModel—adds two-way data binding to an HTML form element.

    - Attribute directives

================

Building Blocks of Angular

-----------------

ngOnInit VS Constructor

OK, first of all ngOnInit is part of Angular lifecycle, while constructor is part of ES6 JavaScript class, 

so the major difference starts from right here!...

===

https://youtu.be/MBJyMW0Onac

=================

https://www.tektutorialshub.com/angular/angular-observable-tutorial-using-rxjs/#reactive-programming


Rx stands from Reactive programming. It is defined as programming with asynchronous data streams.

What is a data stream : 

A stream is a data, which arrives over a period of time. 

Reactive Programming

The reactive programming is all about creating the stream, emitting value, error or complete signals, manipulate, transfer or do something useful with the data streams.

The RxJs has two main players

  1. Observable
  2. Observers ( Subscribers)

What is an Observable in Angular 

observables are declarative which provide support for passing messages between publisher and subscribers in application.

Observable is a function that converts the ordinary stream of data into an observable stream of data. You can think of Observable as a wrapper around the ordinary stream of data.

Observable stream or simple Observable emits the value from the stream asynchronously. It emits the complete signals when the stream completes or an error signal if the stream errors out.

Observables are declarative. You define an observable function just like any other variable. The observable starts to emit values only when someone subscribes to it.

Who are observers (subscribers)

The Observable on its own is useless unless someone consumes the value emitted by the observable. We call them observers or subscribers.

The observers communicate with the Observable using callbacks

The observer must subscribe with the observable to receive the value from the observable. While subscribing it optionally passes the three callbacks. next()error() & complete()

The observable starts emitting the value as soon as the observer or consumer subscribes to it.

  • Observers/subscribers subscribe to Observables
  • Observer registers three callbacks with the observable at the time of subscribing. i .e next()error() & complete()
  • All three callbacks are optional
  • The observer receives the data from the observer via the next() callback
  • They also receive the errors and completion events from the Observable via the error() & complete() callbacks

Comments

Popular posts from this blog

2021

What is webpack