# Load data on demand

With Ember Await you can load your data on-demand (eg. on button click). To do it, we need to use [`@defer=`](https://github.com/Exelord/ember-await/tree/23b6843bfc298d86e322d79eb49d1a2151f6b504/docs/guides/api/arguments.md#defer) argument and call the promise using [`run`](https://github.com/Exelord/ember-await/tree/23b6843bfc298d86e322d79eb49d1a2151f6b504/docs/guides/api/yielded-properties.md#run) property.

**Remember! `this.fetchPosts` needs to return a function**

```
<Await @defer={{this.fetchPosts}} as |await|>
  <button {{on "click" await.run}}>Fetch posts</button>

  <await.Initial>
    No posts are loaded yet
  </await.Initial>

  <await.Fulfilled as |posts|>
    {{#each posts as |post|}}
      {{post.title}}
    {{/each}}
  </await.Fulfilled>
</Await>
```

This way, the content from `await.Initial` will be displayed until we click the `button` and posts will load.


---

# 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://exelord.gitbook.io/ember-await/guides/load-data-on-demand.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.
