🔥 Free eBook: Anguar Standalone Components and APIs
Practical eBook with lots of Examples | PDF | ePUB
Standalone Components are the beginning of a new area of Angular development! Beginning with Angular 14, they make NgModules optional and hence your Angular applications more streightforward and lightweight.
Using lots of examples, this free practical eBook shows in several chapters how to use Standalone Components and how they influence existing APIs like such for routing and lazy loading.
Your Author: Manfred Steyer, GDE
[download]
Practical eBook with lots of Examples | PDF | ePUB
Standalone Components are the beginning of a new area of Angular development! Beginning with Angular 14, they make NgModules optional and hence your Angular applications more streightforward and lightweight.
Using lots of examples, this free practical eBook shows in several chapters how to use Standalone Components and how they influence existing APIs like such for routing and lazy loading.
Your Author: Manfred Steyer, GDE
[download]
👍4
#angular inject() function
inject is a function that takes the injectionToken as an argument and returns the value for that token from the currently active injector.
inject() can be called only from an injection context ( constructor function, factory function, or a field initializer phase ), which means we cannot use inject() inside any methods, or any life cycle hooks
To put it in simple terms, It's just another way to inject dependencies into components/directives/pipes.
The problem it solves:-
• Usually, we inject dependency into a component via the constructor of the component class, which means whenever we need a dependency, we need a class with a constructor to inject that dependency.
but using inject() function we can keep our business logic in a separate function where we can access any dependencies using inject() function directly and we can re-use it in multiple components by just importing & invoking that function.
inject is a function that takes the injectionToken as an argument and returns the value for that token from the currently active injector.
inject() can be called only from an injection context ( constructor function, factory function, or a field initializer phase ), which means we cannot use inject() inside any methods, or any life cycle hooks
To put it in simple terms, It's just another way to inject dependencies into components/directives/pipes.
The problem it solves:-
• Usually, we inject dependency into a component via the constructor of the component class, which means whenever we need a dependency, we need a class with a constructor to inject that dependency.
but using inject() function we can keep our business logic in a separate function where we can access any dependencies using inject() function directly and we can re-use it in multiple components by just importing & invoking that function.