Huy
Huy

Reputation: 11206

#each over an array does not output correctly in handlebar

I have a helper method that takes one of my hashes and creates an array out of the keys:

signup-services-array.js

import Ember from 'ember';

export default Ember.Helper.helper(function(params) {
  var serviceSignups = [];
  var hash = params[0];
  Object.keys(hash).forEach(function(key) {
    serviceSignups.push(key);
  });

  return serviceSignups;
});

In my handlebar view, if I call {{signup-services-array model.signedServices}}, I see the output caviar,doordash,lyft.

However, if I try to iterate over it, I don't see anything:

<ul>
  {{#each signup-services-array model.signedServices as |service|}}
    <li>{{service}}</li>
  {{/each}}
</ul>

How do I loop over the array in handlebar?

Upvotes: 1

Views: 31

Answers (1)

Daniel
Daniel

Reputation: 18672

Try to wrap your helper in ():

<ul>
  {{#each (signup-services-array model.signedServices) as |service|}}
    <li>{{service}}</li>
  {{/each}}
</ul>

Upvotes: 1

Related Questions