Skip to content

Commit 0733efb

Browse files
committed
translate: translations for new DI guides
Fixes #87
1 parent 84148e5 commit 0733efb

File tree

5 files changed

+1274
-246
lines changed

5 files changed

+1274
-246
lines changed

adev-es/src/app/routing/sub-navigation-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ const DOCS_SUB_NAVIGATION_DATA: NavigationItem[] = [
298298
status: 'updated',
299299
},
300300
{
301-
label: 'Creating and using services',
301+
label: 'Crando y usando servicios',
302302
path: 'guide/di/creating-and-using-services',
303303
contentPath: 'guide/di/creating-and-using-services',
304304
status: 'updated',
305305
},
306306
{
307-
label: 'Defining dependency providers',
307+
label: 'Definiendo proveedores de dependencias',
308308
path: 'guide/di/defining-dependency-providers',
309309
contentPath: 'guide/di/defining-dependency-providers',
310310
status: 'updated',
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Creating and using services
2+
3+
Services are reusable pieces of code that can be shared across your Angular application. They typically handle data fetching, business logic, or other functionality that multiple components need to access.
4+
5+
## Creating a service
6+
7+
You can create a service with the [Angular CLI](tools/cli) with the following command:
8+
9+
```bash
10+
ng generate service CUSTOM_NAME
11+
```
12+
13+
This creates a dedicated `CUSTOM_NAME.ts` file in your `src` directory.
14+
15+
You can also manually create a service by adding the `@Injectable()` decorator to a TypeScript class. This tells Angular that the service can be injected as a dependency.
16+
17+
Here is an example of a service that allows users to add and request data:
18+
19+
```ts
20+
// 📄 src/app/basic-data-store.ts
21+
import { Injectable } from '@angular/core';
22+
23+
@Injectable({ providedIn: 'root' })
24+
export class BasicDataStore {
25+
private data: string[] = []
26+
27+
addData(item: string): void {
28+
this.data.push(item)
29+
}
30+
31+
getData(): string[] {
32+
return [...this.data]
33+
}
34+
}
35+
```
36+
37+
## How services become available
38+
39+
When you use `@Injectable({ providedIn: 'root' })` in your service, Angular:
40+
41+
- **Creates a single instance** (singleton) for your entire application
42+
- **Makes it available everywhere** without any additional configuration
43+
- **Enables tree-shaking** so the service is only included in your JavaScript bundle if it's actually used
44+
45+
This is the recommended approach for most services.
46+
47+
## Injecting a service
48+
49+
Once you've created a service with `providedIn: 'root'`, you can inject it anywhere in your application using the `inject()` function from `@angular/core`.
50+
51+
### Injecting into a component
52+
53+
```angular-ts
54+
import { Component, inject } from '@angular/core';
55+
import { BasicDataStore } from './basic-data-store';
56+
57+
@Component({
58+
selector: 'app-example',
59+
template: `
60+
<div>
61+
<p>{{ dataStore.getData() }}</p>
62+
<button (click)="dataStore.addData('More data')">
63+
Add more data
64+
</button>
65+
</div>
66+
`
67+
})
68+
export class ExampleComponent {
69+
dataStore = inject(BasicDataStore);
70+
}
71+
```
72+
73+
### Injecting into another service
74+
75+
```ts
76+
import { inject, Injectable } from '@angular/core';
77+
import { AdvancedDataStore } from './advanced-data-store';
78+
79+
@Injectable({
80+
providedIn: 'root',
81+
})
82+
export class BasicDataStore {
83+
private advancedDataStore = inject(AdvancedDataStore);
84+
private data: string[] = [];
85+
86+
addData(item: string): void {
87+
this.data.push(item);
88+
}
89+
90+
getData(): string[] {
91+
return [...this.data, ...this.advancedDataStore.getData()];
92+
}
93+
}
94+
```
95+
96+
## Next steps
97+
98+
While `providedIn: 'root'` covers most use cases, Angular offers additional ways to provide services for specialized scenarios:
99+
100+
- **Component-specific instances** - When components need their own isolated service instances
101+
- **Manual configuration** - For services that require runtime configuration
102+
- **Factory providers** - For dynamic service creation based on runtime conditions
103+
- **Value providers** - For providing configuration objects or constants
104+
105+
You can learn more about these advanced patterns in the next guide: [defining dependency providers](/guide/di/defining-dependency-providers).

adev-es/src/content/guide/di/creating-and-using-services.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
# Creating and using services
1+
# Creando y usando servicios
22

3-
Services are reusable pieces of code that can be shared across your Angular application. They typically handle data fetching, business logic, or other functionality that multiple components need to access.
3+
Los servicios son piezas de código reutilizables que pueden compartirse a través de tu aplicación Angular. Típicamente manejan la obtención de datos, lógica de negocio u otra funcionalidad que múltiples componentes necesitan acceder.
44

5-
## Creating a service
5+
## Creando un servicio
66

7-
You can create a service with the [Angular CLI](tools/cli) with the following command:
7+
Puedes crear un servicio con el [Angular CLI](tools/cli) con el siguiente comando:
88

99
```bash
1010
ng generate service CUSTOM_NAME
1111
```
1212

13-
This creates a dedicated `CUSTOM_NAME.ts` file in your `src` directory.
13+
Esto crea un archivo dedicado `CUSTOM_NAME.ts` en tu directorio `src`.
1414

15-
You can also manually create a service by adding the `@Injectable()` decorator to a TypeScript class. This tells Angular that the service can be injected as a dependency.
15+
También puedes crear manualmente un servicio añadiendo el decorador `@Injectable()` a una clase TypeScript. Esto le indica a Angular que el servicio puede ser inyectado como una dependencia.
1616

17-
Here is an example of a service that allows users to add and request data:
17+
Aquí hay un ejemplo de un servicio que permite a los usuarios agregar y solicitar datos:
1818

1919
```ts
2020
// 📄 src/app/basic-data-store.ts
@@ -34,21 +34,21 @@ export class BasicDataStore {
3434
}
3535
```
3636

37-
## How services become available
37+
## Cómo los servicios se vuelven disponibles
3838

39-
When you use `@Injectable({ providedIn: 'root' })` in your service, Angular:
39+
Cuando usas `@Injectable({ providedIn: 'root' })` en tu servicio, Angular:
4040

41-
- **Creates a single instance** (singleton) for your entire application
42-
- **Makes it available everywhere** without any additional configuration
43-
- **Enables tree-shaking** so the service is only included in your JavaScript bundle if it's actually used
41+
- **Crea una única instancia** (singleton) para toda tu aplicación
42+
- **Lo hace disponible en todas partes** sin ninguna configuración adicional
43+
- **Habilita tree-shaking** para que el servicio solo se incluya en tu bundle de JavaScript si realmente se usa
4444

45-
This is the recommended approach for most services.
45+
Este es el enfoque recomendado para la mayoría de los servicios.
4646

47-
## Injecting a service
47+
## Inyectando un servicio
4848

49-
Once you've created a service with `providedIn: 'root'`, you can inject it anywhere in your application using the `inject()` function from `@angular/core`.
49+
Una vez que has creado un servicio con `providedIn: 'root'`, puedes inyectarlo en cualquier parte de tu aplicación usando la función `inject()` de `@angular/core`.
5050

51-
### Injecting into a component
51+
### Inyectando en un componente
5252

5353
```angular-ts
5454
import { Component, inject } from '@angular/core';
@@ -70,7 +70,7 @@ export class ExampleComponent {
7070
}
7171
```
7272

73-
### Injecting into another service
73+
### Inyectando en otro servicio
7474

7575
```ts
7676
import { inject, Injectable } from '@angular/core';
@@ -93,13 +93,13 @@ export class BasicDataStore {
9393
}
9494
```
9595

96-
## Next steps
96+
## Próximos pasos
9797

98-
While `providedIn: 'root'` covers most use cases, Angular offers additional ways to provide services for specialized scenarios:
98+
Aunque `providedIn: 'root'` cubre la mayoría de los casos de uso, Angular ofrece formas adicionales de proveer servicios para escenarios especializados:
9999

100-
- **Component-specific instances** - When components need their own isolated service instances
101-
- **Manual configuration** - For services that require runtime configuration
102-
- **Factory providers** - For dynamic service creation based on runtime conditions
103-
- **Value providers** - For providing configuration objects or constants
100+
- **Instancias específicas de componente** - Cuando los componentes necesitan sus propias instancias aisladas de servicio
101+
- **Configuración manual** - Para servicios que requieren configuración en tiempo de ejecución
102+
- **Proveedores factory** - Para creación dinámica de servicios basada en condiciones de tiempo de ejecución
103+
- **Proveedores de valor** - Para proveer objetos de configuración o constantes
104104

105-
You can learn more about these advanced patterns in the next guide: [defining dependency providers](/guide/di/defining-dependency-providers).
105+
Puedes aprender más sobre estos patrones avanzados en la siguiente guía: [definiendo proveedores de dependencias](/guide/di/defining-dependency-providers).

0 commit comments

Comments
 (0)