Each helper only works as {{#each model as |blah|}}?


#1

In my starter app I’m using the latest ember-cli, ember, with htmlbars. The handlebars dependency has been removed from my app.

I have the same issue whether I hash two models together or use a single model. That is that the only syntax I can get to work for the #each is {{#each model as |blah|}}. Can anyone explain why this is?

Route

route.js

import Ember from 'ember';
export default Ember.Route.extend({
 model() {
  return this.store.find('employee'); } });

Model

model.js

import DS from 'ember-data';
export default DS.Model.extend({
   firstName: DS.attr('string'),
    lastName: DS.attr('string'),  ....etc

Template

<tbody>
{{#each model as |employee|}}

  <tr>
  <td>{{employee.firstName}}</td>
  <td>{{employee.lastName}}</td>
  </tr>
{{/each}}

{{#each employee as |employee|}} or {{#each employees as |employee|}} make the table blank. It only works if I do each {{#each model as …}}.

I have the same thing if I hash together two models using the RSVP.hash.

Thoughts?


#2

You’re naming your collection model in your router. That is why you need model in your each statement. If you named it ‘employees’, then you could use ‘employees’

{{each employees as |employee|| }}

I however like to stick with model for simplicity. You can also use the following format:

{{#each employee in model }}

…and achieve the same template usage.