Posts

Showing posts with the label Angular

Add key-value pair to every object in array of objects in JavaScript

Image
Sometimes, we've to add flag or some new key-value pair to every object in array of objects. For that we can follow three ways to achieve it. For suppose, we have an array of objects as below and we want to add gender key to all the objects     students  = [     {        name:   'Radhika' ,        age:   26 ,     },     {        name:   'Radha' ,        age:   24 ,     },     {        name:   'Jyothi' ,        age:   25 ,     },   ]; // Expected Output    students  = [     {        name:   'Radhika' ,        age:   ...

Avoiding multiple API calls in Angular by using shareReplay method of RxJS

Image
While working with some Angular projects, we've to subscribe the same api in to different methods in a component. In order to avoid that we can use shareReplay method of RxJS. Lets consider an app which has two buttons and two different methods gets called on clicking on those buttons. But, internally the two methods will subscribe the same api two times. Suppose user clicks the button multiple times, then we've to call the same api multiple times to display the number of completed/incomplete tasks. On clicking the `Completed Todos` and `Incomplete Todos` buttons, same API got two times. This will increase the load on server and increase the loading time of UI. Henceforth, reduces the performance of our application. We can avoid calling multiple API services with the help of shareReplay method of RxJS. shareReplay  subscribes the observable, caches the response and multicasts it to all the subscribers without calling the API multiple times. Lets see the above example with share...

Angular Interview Questions

Image
If you are here reading this post, you might be preparing for interviews. I promise that I'll jot down the most frequently asked interview questions  and answers based on my interview experience as of 2021.  H ope this article will help you in cracking your dream job. 1.What is Angular? Angular is an open-source web application framework that uses TypeScript programming language. Developed by Google. Framework: Predefined structure of something. 2. What is AngularJS? Angular is an open-source web application framework that uses JavaScript programming language.  Developed by Google. It is an older version of Angular. 3. What are the differences between AngularJS and Angular? AngularJS : AngularJS is actually the first version of Angular (Angular1). AngularJS framework uses JavaScript language. It is not supported on mobile devices. It is slower than Angular. It doesn’t support dependency injection. It follows MVC architecture. Managing huge applications is difficult. Angul...