⌚
Ember Await
  • Introduction
  • Getting started
    • Installation
    • Usage
  • Guides
    • Migrate from routes
    • Load data on demand
  • API
    • Interfaces
    • Arguments
    • Yielded properties
    • Yielded components
  • Misc
    • Contributing
    • License
Powered by GitBook
On this page

Was this helpful?

  1. Guides

Load data on demand

PreviousMigrate from routesNextInterfaces

Last updated 5 years ago

Was this helpful?

With Ember Await you can load your data on-demand (eg. on button click). To do it, we need to use argument and call the promise using 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.

@defer=
run