# Injection d'un Service Angular

## Qu'est-ce qu'un service Angular ?

Avec Angular, **une dépendance** est généralement l'instance d'une classe permettant de **factoriser certaines fonctionnalités** ou d'**accéder à un état** permettant ainsi aux composants de communiquer entre eux.

Dans le vocabulaire Angular, ces classes sont appelées "**services"**.

Les services sont le plus souvent **des singletons**. Cf. [Portée des Services](/angular/dependency-injection/portee-des-services.md).

## Injection d'un service Angular

Un service Angular peut être injecté par n'importe quelle classe Angular *(i.e. : composant,* [*Directive*](/angular/directives.md)*,* [*Service*](/angular/dependency-injection/services-and-providers.md) *ou* [*Pipe*](/angular/pipes.md)*)* via les paramètres de son constructeur.

{% tabs %}
{% tab title="book-preview\.component.ts" %}

```typescript
@Component({
    ...
})
export class BookPreviewComponent {

    constructor(private _httpClient: HttpClient) {
    }

}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Vous remarquerez l'utilisation des [TypeScript Parameter Properties](/typescript/typing-des-proprietes.md#raccourci-pour-les-parametres-ordonnees-du-constructeur) afin de copier le service `HttpClient` dans la propriété `_httpClient`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guide-angular.wishtack.io/angular/dependency-injection/injection-dun-service-angular.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
