I am using ember ( v 3.0) service to fetch customer data . when i am calling same service from template , it not showing any data .
following are the code
//service.js
export default Service.extend({
store: Ember.inject.service(),
cutomers : null,
getProperty() {
var list = this.get('store').findAll('customer');
this.set('cutomer', list );
return this.get('cutomers');
}
});
The code is not well formatted, but if I got it right, customers property of your customerList service is null. getProperty method of your service sets a customer property to a PromiseProxy returned by ember-data’s store service. I think this should set customers property, isn’t it? So to put it together: there seems to be a typo and I don’t see getProperty called anywhere in the code snippets you provided. Make sure it’s called.
In general I don’t think this is good code. Is there any reason you are not using a Route’s model to load customerList? If fetching the data via service, I would use a computed property to make sure it’s fetched on first request.
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
export default Service.extend({
store: service(),
customers: computed(function() {
return this.get('store').findAll('customer');
})
});
This is doing the same as your service but does not require to execute getProperty() before customers property is available.
ya i know its not gud code ( i m new on ember ) the reason behind not using route is customer is different model and it has heavy load . when i use through the route it take total 27 to 38 sec to load data.