Q41. What do you mean by term tree shaking?
Q42. What are services in angular? for what purpose they are used? can we do api hit using any other class? can we user dependency injection with othe class and also data sharing without services?
Q43. What is dependency injection in angular?
Q44. What are pipes? what are different types of pipes?
Q45. How to create a custom pipes?
--------------------------------------------------------------------------------------------------------------------------
Q41. What do you mean by term tree shaking?
Answer 41:
Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code
Tree shaking is the ability to remove any code that we are not actually using in our application from the final bundle. It's one of the most effective techniques to reduce the footprint of an application.
If you're using webpack, for example, you can simply set the mode to production in your webpack. config. js configuration file. This will, among other optimizations, enable tree shaking
--------------------------------------------------------------------------------------------------------------------------
Q42. What are services in angular? for what purpose they are used? can we do api hit using any other class? can we user dependency injection with othe class and also data sharing without services?
Answer 42:
Angular services are singleton objects that get instantiated only once during the lifetime of an application. They contain methods that maintain data throughout the life of an application, i.e. data does not get refreshed and is available all the time. The main objective of a service is to organize and share business logic, models, or data and functions with different components of an Angular application
The separation of concerns is the main reason why Angular services came into existence. Angular Services are usually implemented through dependency injection
Answer 43:
DI is a coding pattern in which a class receives its dependencies from external sources rather creating them itself. Most of the time in Angular, dependency injection is done by injecting a service class into a component or module class.'
Injector is like a container where all you dependencies are registered. Service class in angular will act like a regular class unless we register it to injector.
To register a service we use provider meta data. We can use provider metadeta at module class level or at component level.
--------------------------------------------------------------------------------------------------------------------------
Q42. What are services in angular? for what purpose they are used? can we do api hit using any other class? can we user dependency injection with othe class and also data sharing without services?
Q43. What is dependency injection in angular?
Q44. What are pipes? what are different types of pipes?
Q45. How to create a custom pipes?
--------------------------------------------------------------------------------------------------------------------------
Q41. What do you mean by term tree shaking?
Answer 41:
Tree shaking is a term commonly used within a JavaScript context to describe the removal of dead code
Tree shaking is the ability to remove any code that we are not actually using in our application from the final bundle. It's one of the most effective techniques to reduce the footprint of an application.
If you're using webpack, for example, you can simply set the mode to production in your webpack. config. js configuration file. This will, among other optimizations, enable tree shaking
--------------------------------------------------------------------------------------------------------------------------
Q42. What are services in angular? for what purpose they are used? can we do api hit using any other class? can we user dependency injection with othe class and also data sharing without services?
Answer 42:
Angular services are singleton objects that get instantiated only once during the lifetime of an application. They contain methods that maintain data throughout the life of an application, i.e. data does not get refreshed and is available all the time. The main objective of a service is to organize and share business logic, models, or data and functions with different components of an Angular application
The separation of concerns is the main reason why Angular services came into existence. Angular Services are usually implemented through dependency injection
--------------------------------------------------------------------------------------------------------------------------
Q43. What is dependency injection in angular?Answer 43:
DI is a coding pattern in which a class receives its dependencies from external sources rather creating them itself. Most of the time in Angular, dependency injection is done by injecting a service class into a component or module class.'
Injector is like a container where all you dependencies are registered. Service class in angular will act like a regular class unless we register it to injector.
To register a service we use provider meta data. We can use provider metadeta at module class level or at component level.
--------------------------------------------------------------------------------------------------------------------------
Q44. What are pipes? what are different types of pipes?
Answer 44:
Answer 44:
Pipe transforms the data in the format as required and displays the same in the view (browser).
example of some built-in pipes.
- Lowercase
- Uppercase
- Date
- Currency
- Json
- Percent
- Decimal
- Slice - first argument as starting index and 2nd argument is length
- title - make every first letter of sentence capital
- number- a.b-c; a is minimum number of digits before decimal. b is minimum number of digits after decimal. c is maximum number of digits after decimal.
We can use multiple pipes combination as well eg. date pipe with uppercase pipe.
There are mainly two types of pipes 1) built in pipes and 2) Custom pipes.
--------------------------------------------------------------------------------------------------------------------------
Q45. How to create a custom pipes?
Answer 45:
Lets say we can to create a custom pipe witch will append 'MR' in front of name if we have gender = male and 'MISS' if we have gender = female.
Q45. How to create a custom pipes?
Answer 45:
Lets say we can to create a custom pipe witch will append 'MR' in front of name if we have gender = male and 'MISS' if we have gender = female.
- Name of a pipe typescript file is <<pipename>>.pipe.ts
- import pipe and pipetransform from angular/core.
- define pipe decorator.
- Create a new class and export it so that other class can use it.
- Implements an interface pipetransform
- Declare the method transform. This method actually takes input parameters and gives the expected output parameters.
- import the pipe on app.module.ts file and add it in declarations with components.
- ready to use pipes.
No comments:
Post a Comment