How to show message for an empty model instead of loading in hbs template, each or if


#1

I use very often in my code (and I don’t know if I’m right to use it):

{{#each model.posts as |post|}}

  <div>post.title</div>

{{else}}

  <div>I'm loading the posts...</div>

{{/each}}

and until today everything OK.

But now I don’t know if the model.posts is empty or not.

How to show an error instead of loading forever an empty array?


#3

Which version of Ember do you use? In the API docs, the behaviour of the {{each}}-Helper is just described as you say Ember API Docs - Ember.Templates.helpers


#4

Yes but the problem is not the {{each}}.


#5

oh, ok. I’m sorry but I thought that the {{else}} is what doesn’t happen and therefore you don’t know if the array is empty or not…? I’m no native speaker so sorry if I got you wrong :slight_smile:


#6

I’m using the isPending property on a hasMany model like this:

{{#if model.posts.isPending}}
  <div>I'm loading the posts...</div>
{{else}}
  {{#each model.posts as |post|}}
    <div>{{post.title}}</div>
  {{else}}
    <div>There are no posts</div>
  {{/each}}
{{/if}}

#7

There is a problem with this code, how to solve? See: http://stackoverflow.com/questions/43104941/blink-from-loading-ispending-to-resolved-why