⌚
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. Getting started

Usage

PreviousInstallationNextMigrate from routes

Last updated 5 years ago

Was this helpful?

Use <Await /> component to load your data in your components. You can take advantage of , like Pending, Fulfilled or Rejected to define your UI based on promise state, example:

  <Await @promise={{this.fetchPosts}} as |await|>
    <await.Pending>
      Loading posts...
    </await.Pending>

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

    <await.Rejected>
      Something went wrong :(
    </await.Rejected>
  </Await>

You can also control the state yourself using , where you can access isPending, isRejected etc...

  <Await @promise={{this.fetchPosts}} as |await|>
    <div class={{if await.isPending "loading"}}>
      Hey there :) This text will spin when content is loading.
    </div>
  </Await>

Your @promise can be anything. A promise, function which returns promise, a task (from ember-concurrency) or normal string. Sky is the limit.

You can also load the promise on demand using @defer:

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

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

More Guides are coming soon!

For more useful patterns in Ember Await check out the rest of the documentation and visit for reference.

Yielded Components
Yielded properties
React Async