When we register providers in @NgModule(), angular internally includes all those related classes in the final bundle, irrespective of their actual use in the application. To overcome this, it is recommended to use @Injectable() decorator when creating a service as below:
@Injectable({
providedIn: 'root'
})
export class MyShakeableService {
// some logic
}
This enables the Angular to inspect which services are actually being used in the application and 'exclude' unused service classes from the final bundle - there by reducing the bundle size. These kind of providers are called as 'tree shakeable'. This was introduced in Angular 6.
Angular • Added 3 months ago
The below are the lifecycle hooks available in Angular. These are added by implementing the respective interface on the component. 1. ngOnChange - ...
* A subject is a special type of Observable which shares a single execution path among the observers which results in a multicast (one to many). * Th ...
1. Import and add RouterModule to the modules in NgModule 2. Declare a routes array which contains all the routes and their endpoints and then pass t ...
* When you register a service into DI in Angular, the services are marked Singleton. * Alternatively to create a transient service (a new instance o ...
parseInt() and Number() are both used to convert a string into a number. * parseInt() parses the value of the string and converts to number till th ...