EmberSherpa / ama

Ask me anything Ember!
22 stars 0 forks source link

How can I load data in an ember view/template/component directly, not from a route #9

Open ghost opened 9 years ago

ghost commented 9 years ago

I have a route:

/foo/1/foobar2

That loads data from a web service. In the template it loops through {{#each}} record and builds a up a display. Part of that display (a bootstrap tab) needs data from a different web service that wasn't loaded in the route. This web service needs a value from the {{#each}} record that's the foreign key to lookup and display a small set of related objects.

What's the correct ember mechanism for doing this?

lukesargeant commented 9 years ago

If you want to wrap the web service response in an Ember Data model, then you can inject the store into the component instead and just use it from your component.

If you aren't confident with Ember Data then you could create an ember 'service' that talks to the web service using standard AJAX requests. Then use an initializer to inject that service into the components that need it and just get the data when you init the component.