Angular - Things you must know.

Angular - Things you must know.

Question 01. Advantages and disadvantages which you know in angular?

Every interviewer like to ask this question at the very beginning of every interview because it perfectly shows how broad the knowledge candidate does have and how many features in angular he or she uses. You can mention everything you like or don't like in angular and the more the better advantages.

Advantages

  1. Typescript support.
  2. Powerful CLI
  3. Dependency injection.
  4. All in one solution fully-fledged framework which comes with its own routing animations form and , etc

Disadvantages

  1. Complexity - comparing two other frameworks like react js or Vue js besides some framework-specific features you have to learn also typescript which takes some time and also RXJS library and the last one is even more challenging and without solid knowledge in RXJS, your code will turn into unmaintainable very soon.
  2. Bundle size - angular is quite thick but there are some ways how to decrease this bundle size, especially in the shell bundle size angular team does a very good job towards the optimization, and usually it gets better with every major release.
  3. Community size and if comparing to react community angular community is smaller but it is not a small mean that you have no any problems with third third-party libraries or answers at the stack overflow everything is completely perfect there but it's just smaller than react community.


Question 02. What is change detection? What is this and how does it work?

Change detection is a mechanism after the view is rendered in case data was changed it is triggered when one of the next events happened.

When an AJAX call was performed and the last thing when some set interval or set timeout was ticked once it happens angular start traversing the tree of components and this traversing is a quite heavy operation and it can be the cause of their performance issues and on another way of how to optimize it is ng on push strategy by setting up our own push change detection strategy you are telling Angular to perform change detection only in next cases.

No alt text provided for this image

it's important to unsubscribes from the stream in case if the component has been destroyed

Question 03. Dependency injection and how it works?

Dependency injection is an application design pattern which has its own implementation in angular and the main idea of this pattern is when a class delegates a creation and providing some external dependencies to some external resource.

There are two types of injectors

Model injector - which can be configured inside ng model and injectable annotations

No alt text provided for this image

Element injector - injector which is being created for every DOM element and can be configured inside the component or directive annotation. Inside this directive or component annotation, you have this provider's property to providers array where you provide some services whatever. These two type of injectors they have its own hierarchy

No alt text provided for this image

How does angular resolves these dependencies?

When the component declares some dependency angular first of all tries to resolve it in its own element injector of these components which declares this dependency. If there is no provider for it angular asks a parent element injector and then in continues to go up until it is finds it.

No alt text provided for this image

if it cannot resolve even in the model injector hierarchy you will get most probably the error (null inject).

Question 04. what is RXJS?

A library that implements the concept of reactive programming and this library is heavily used in the angular application you are not able to avoid using?RXJS in the angular application

so you must understand at least some core concepts of this. The most popular question about this topic is, what the difference between observables and streams compared to promises.

Difference between observables and streams comparing to promises.

No alt text provided for this image


  • Observables are lazy so you have to call subscribe method in order to execute
  • Promise (Eager) is being executed immediately.
  • Observable are cancelable.
  • Promises are not cancelable.
  • Observable can be sync also async.
  • Promise it's always async.
  • Observable can emit multiple values promise can emit only one value.
  • Observable has different operators to transform the data.
  • Promises have only then and catch and finally methods.

It is important to know RXJS operators and you need to really pay attention to operators like SwitchMap(), map(), and contact() are worked and also some combined them in practical use because it is a really bad sign if you don't know how to combine them. Later on, you can see in your code base something like subscribe inside subscribed and subscribed.

It is important to know the subject in RXJS and what kind of subject you know so there are subjects just Subject, BehaviorSubject, ReplaySubject?and AsyncSubject

To prevent memory leaks

Kill every subscription, if you destroy some particular component and async pipe we have to use as much as we can because it cares about unsubscription as well so very handy.

要查看或添加评论,请登录

Hasitha Madusanka的更多文章

社区洞察

其他会员也浏览了