Making Angular Service – Always  Singleton

By default, Angular Services are Singleton. When you create a service using the CLI command, ng g s App Angular creates a service named AppService. https://gist.github.com/debugmodedotnet/17b2ff1a9050ae4d9530fd75b99d99ce The above service is SingletonTree-shakeableAvailable throughout the application Singleton means Angular creates only one object of the AppService, regardless of how many places you use it. However, if youContinue reading "Making Angular Service – Always  Singleton"

The simplest way to disable console.log for Production build in Angular?

I work with different developers, and most of them rely on console.log () or other console methods for development. They use the console to print various values to debug while doing the development. I call this approach console-driven development. Cool name, right? These console functions become overwhelming in production as users can see many thingsContinue reading "The simplest way to disable console.log for Production build in Angular?"

Make all properties optional using Partial in TypeScript

The utility type Partial<Type> makes all properties of a type optional. Using a scenario, let us try to understand Partial<T> in TypeScript. So, you have a type called Product, that is created as below:   export interface Product {   Id: string;   Title: string;   Price: number;   inStock: boolean;   Quantity: number; } And there is a function to update the price of a product as shownContinue reading "Make all properties optional using Partial in TypeScript"

Video – Master JavaScript ‘this’ in 30 Mins

Do you know, there are four ways to calculate the value of 'this' inside a JavaScript function?  Some pointers about 'this'  Every function has it's own 'this' An arrow function does not have it's own 'this'The value of 'this' depends on, how that function is called. The value of 'this does not depend on how the functionContinue reading "Video – Master JavaScript ‘this’ in 30 Mins"

JavaScript function is also a constructor?

JavaScript function is also a “constructor.” You must have heard it many times, haven’t you? Well, that is a wrong way of interpreting the JavaScript function; even though you can create an object using a function, it does not mean you can call it a constructor. Let us discuss it: There are four ways toContinue reading "JavaScript function is also a constructor?"

Video – Angular Interview : is Angular Service Singleton ?

One of the most popular Angular interview questions is, whether a service is singleton? By default, when you create a service using the below CLI command, ng g s app AppService is singleton, however it can be re-provided to create more objects of it. Say, you again re provide AppService in one of the components,Continue reading "Video – Angular Interview : is Angular Service Singleton ?"