> For the complete documentation index, see [llms.txt](https://ng-girls.gitbook.io/todo-list-tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ng-girls.gitbook.io/todo-list-tutorial/workshop-todo-list/add-items-using-the-service.md).

# #16: 🎁 Add Items Using the Service

Let's improve our service by adding more abilities that will be used by our components. First - we'll implement adding an item to the list.

## Adding an item

We'll add a new method to the service, called `addItem`, like so:

{% code title="src/app/services/todo-list.service.ts" %}

```typescript
addItem(item: TodoItem) { 
  this.todoList.push(item);
}
```

{% endcode %}

Now we can change our `list-manager` component to call the `addItem` method directly from the service:

{% code title="src/app/list-manager/list-manager.component.ts" %}

```typescript
addItem(title: string) {
    this.todoListService.addItem({ title });
}
```

{% endcode %}

* Note that the service's method expects the whole item, while the component's method expects only the title and constructs the item. (You may decide to let the service construct the item from the title.)
* There may be additional logic when calling these methods, i.e. saving the changes in a database (which we'll implement later).
* A better way to handle data is using *immutable objects*, but that's a bigger topic than we can cover in this tutorial at the moment.

{% hint style="info" %}
💾 **Save your code to GitHub**

StackBlitz users - press **Save** in the toolbar and continue to the next section of the tutorial.

Commit all your changes by running this command in your project directory.

```
git add -A && git commit -m "Your Message"
```

Push your changes to GitHub by running this command in your project directory.

```
git push
```

{% endhint %}

{% hint style="success" %}
[See the results on StackBlitz](https://stackblitz.com/github/ng-girls/todo-list-tutorial/tree/master/examples/0_16-add-items-using-the-service)
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ng-girls.gitbook.io/todo-list-tutorial/workshop-todo-list/add-items-using-the-service.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
