Creating services
Services in Angular are TypeScript classes that aim to implement business logic for our interfaces. Business logic in a frontend project can seem like a controversial issue because ideally, all logic and processing should take place on the backend, which is correct.
Here we are using business rules; these rules are generic behaviors that do not depend on a visual component and can be reused in other components.
Examples of frontend business rules could be as follows:
- Application state control
- Communication with the backend
- Information validations with a fixed rule, such as the number of digits in a telephone number
We are going to put this concept into practice, and in our gym diary application, we are going to create the first service. In the command line we will use the Angular CLI:
ng generate service diary/services/ExerciseSets
Unlike the component, we can see that the element created by the Angular CLI is composed only of a TypeScript...