You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* It imports the `CommonModule` because the module's component needs common directives.
30
+
* It declares and exports the utility pipe, directive, and component classes.
31
+
* It re-exports the `CommonModule` and `FormsModule`.
32
+
33
+
By re-exporting `CommonModule` and `FormsModule`, any other module that imports this
34
+
`SharedModule`, gets access to directives like `NgIf` and `NgFor` from `CommonModule`
35
+
and can bind to component properties with `[(ngModel)]`, a directive in the `FormsModule`.
36
+
37
+
Even though the components declared by `SharedModule` might not bind
38
+
with `[(ngModel)]` and there may be no need for `SharedModule`
39
+
to import `FormsModule`, `SharedModule` can still export
40
+
`FormsModule` without listing it among its `imports`. This
41
+
way, you can give other modules access to `FormsModule` without
42
+
having to import it directly into the `@NgModule` decorator.
43
+
44
+
### Using components vs services from other modules
45
+
46
+
There is an important distinction between using another module's component and
47
+
using a service from another module. Import modules when you want to use
48
+
directives, pipes, and components. Importing a module with services means that you will have a new instance of that service, which typically is not what you need (typically one wants to reuse an existing service). Use module imports to control service instantiation.
49
+
50
+
The most common way to get a hold of shared services is through Angular
51
+
[dependency injection](guide/dependency-injection), rather than through the module system (importing a module will result in a new service instance, which is not a typical usage).
52
+
53
+
To read about sharing services, see [Providers](guide/providers).
Creating shared modules allows you to organize and streamline your code. You can put commonly
4
-
used directives, pipes, and components into one module and then import just that module wherever
5
-
you need it in other parts of your app.
3
+
La creación de módulos compartidos te permite organizar y optimizar tu código. Puedes colocar directivas, `pipes`, y componentes de uso común en un módulo y despues importar solo ese módulo donde lo necesites en otras partes de tu aplicación.
6
4
7
-
Consider the following module from an imaginary app:
5
+
Considera el siguiente módulo de una aplicación imaginaria:
8
6
9
7
10
8
```typescript
@@ -24,39 +22,33 @@ import { OrdersPipe } from './orders.pipe';
24
22
exportclassSharedModule { }
25
23
```
26
24
27
-
Note the following:
25
+
Ten en cuenta lo siguiente:
28
26
29
-
*It imports the `CommonModule`because the module's component needs common directives.
30
-
*It declares and exports the utility pipe, directive, and component classes.
31
-
*It re-exports the `CommonModule`and`FormsModule`.
27
+
*Esto importa `CommonModule`porque el componente del módulo necesita directivas comunes.
28
+
*Declara y exporta las clases de componentes, directivas y `pipes`
29
+
*Esto reexporta `CommonModule`y`FormsModule`.
32
30
33
-
By re-exporting`CommonModule`and`FormsModule`, any other module that imports this
34
-
`SharedModule`, gets access to directives like`NgIf`and`NgFor`from`CommonModule`
35
-
and can bind to component properties with `[(ngModel)]`, a directive in the`FormsModule`.
31
+
Al reexportar`CommonModule`y`FormsModule`, cualquier otro módulo que importe este
32
+
`SharedModule`, obtiene acceso a directivas como`NgIf`y`NgFor`desde`CommonModule`
33
+
y puede vincularse a las propiedades del componente con `[(ngModel)]`, a una directiva en`FormsModule`.
36
34
37
-
Even though the components declared by `SharedModule` might not bind
38
-
with `[(ngModel)]` and there may be no need for `SharedModule`
39
-
to import `FormsModule`, `SharedModule` can still export
40
-
`FormsModule` without listing it among its `imports`. This
41
-
way, you can give other modules access to `FormsModule` without
42
-
having to import it directly into the `@NgModule` decorator.
35
+
Aunque los componentes declarados por `SharedModule` pueden no vincularse con `[(ngModel)]` y puede que no sea necesario que `SharedModule` importe `FormsModule`, `SharedModule` aún puede exportar
36
+
`FormsModule` sin incluirlo entre sus `imports (importaciones)`. De esta manera, puedes dar acceso a otros módulos a `FormsModule` sin tener que importarlo directamente al decorador `@NgModule`.
43
37
44
-
### Using components vs services from other modules
38
+
### Uso de componentes vs servicios de otros módulos
45
39
46
-
There is an important distinction between using another module's component and
47
-
using a service from another module. Import modules when you want to use
48
-
directives, pipes, and components. Importing a module with services means that you will have a new instance of that service, which typically is not what you need (typically one wants to reuse an existing service). Use module imports to control service instantiation.
40
+
Existe una distinción importante entre usar el componente de otro módulo y utilizar un servicio de otro módulo. Importa módulos cuando quieras usar directivas, `pipes` y componentes. Importar un módulo con servicios significa que tendrá una nueva instancia de ese servicio, que normalmente no es lo que necesitas (normalmente, quieres reutilizar un servicio existente). Utiliza las importaciones de módulos para controlar la creación de instancias de servicios.
49
41
50
-
The most common way to get a hold of shared services is through Angular
51
-
[dependency injection](guide/dependency-injection), rather than through the module system (importing a module will result in a new service instance, which is not a typical usage).
42
+
La forma más común de obtener servicios compartidos es através de la
43
+
[inyección de dependencia](guide/dependency-injection) en Angular, en lugar de a través del sistema del módulo (la importación de un módulo dará como resultado una nueva instancia de servicio, que no es un uso típico).
52
44
53
-
To read about sharing services, see [Providers](guide/providers).
45
+
Para leer acerca de compartir servicios, consulta [Proveedores](guide/providers).
54
46
55
47
56
48
<hr />
57
49
58
-
## More on NgModules
50
+
## Más en NgModules
59
51
60
-
You may also be interested in the following:
61
-
*[Providers](guide/providers).
62
-
*[Types of Feature Modules](guide/module-types).
52
+
También te puede interesar lo siguiente:
53
+
*[Proveedores](guide/providers).
54
+
*[Tipos de Módulos de funciones](guide/module-types).
0 commit comments