Mads K
Mads K

Reputation: 837

Ember Data won't fetch from API

Even though i have set the RESPAdapter to take care of everything, it doesn't reach out to my server to get the data. My code is:

var App = Ember.Application.create({
  LOG_TRANSITIONS: true
});

App.ApplicationAdapter = DS.RESTAdapter.extend({
  host: '../api/'
});

App.Me = DS.Model.extend({
    email: DS.attr('string'),
    firstname: DS.attr('string'),
    lastname: DS.attr('string')
});

App.WelcomemessageController = Ember.Controller.extend({
    firstname:"I get rendered as i should",
    model: function() {
        return this.store.find('me');
    }
});

And yeah, the property "firstname" gets rendered out just fine. And when inspecting with Chrome Devtools, no requests are being made.

Upvotes: 1

Views: 65

Answers (1)

Kingpin2k
Kingpin2k

Reputation: 47367

In your case you just want to use a computed property, and not the model function. you could call it model, but it'd be slightly confusing since generally a controller decorates a model, and in this case it'd just be a property called model on the controller (in order to decorate a model, the controller needs to be an ObjectController or ArrayController)

App.WelcomemessageController = Ember.Controller.extend({
    firstname:"I get rendered as i should",
    user: function() {
        return this.store.find('me');
    }.property()
});

Upvotes: 1

Related Questions