Search This Blog

Q26-Q30

Q26. What is Zone in Angular 4?
Q27. Two modules are in same zone or different? if different how data transfer between them
Q28. What are BehaviorSubject in angular 4?
Q29. How to call java script on the fly in NG2? What is lazy loading in NG4?
Q30. 
What do you mean by subscribe to an observables?
---------------------------------------------------------------------------------
Q26. What is Zone in Angular?

Answer:

Zone concept is related to how Angular 2 + handles the change detection. Zone.js is the file.
Check #Angular 71

In angular 1 for 3rd party scripts you have to call $apply() to trigger change detection but in angular 2 everything happen implicitly as long as changes are inside app's Zone.

ngZone gives two control of code execution
1st runOutsideAngular, when we want to run outside angular Zone.
2nd safeNgZone, when we want to get back into angular 2 zone.

https://blog.thoughtram.io/angular/2016/02/01/zones-in-angular-2.html
---------------------------------------------------------------------------------
Q27. Two modules are in same zone or different? if different how data transfer between them.

Answer:

Not only two modules, all building blocks of angular are within same zone as long as they are part of same angular application. 
---------------------------------------------------------------------------------
Q28. What are BehaviorSubject  in angular 4?

Answer:

BehaviorSubject is a type of subject, a subject is a special type of observable so you can subscribe to messages like any other observable.

 The unique features of BehaviorSubject are:
1. It is an observer in addition to being an observable so you can also send values to a subject in addition to subscribing to it.
2. It needs an initial value as it must always return a value on subscription even if it hasn't received a next().

https://stackoverflow.com/questions/39494058/behaviorsubject-vs-observable
---------------------------------------------------------------------------------
Q29. How to implement lazy loading in NG2 or NG4?

Answer:

Lazy loading allows you to load features(your created) module on demand.  This technique is used when our application has multiples modules and we dont want all modules to eagerly load with route module (app.module.ts). We use routing module and load modules based on demand. 
https://angular.io/guide/lazy-loading-ngmodules

We achieve this in following steps:

  1. Create a new app. ng new customer-app --routing. This will create a new app with default module app.module.ts and default app-routing.module.ts
  2. Create a feature module with routing. ...
  3. .........
---------------------------------------------------------------------------------
Q30. What do you mean by subscribe to an observables?

Answer:




No comments:

Post a Comment