Reputation: 524
I would like to obtain the host address of the REST adapter in a controller or in a component.
I'm using Ember-CLI, and I set up the adapter as follows:
export default DS.RESTAdapter.extend({
host: 'http://localhost:9000'
});
I am aware that this question has been asked here and here, but none of those approaches work in the recent Ember 1.6.0.
I tried all of the following:
DS.RESTAdapter.prototype.url
DS.RESTAdapter.prototype.host
App.__container__.lookup('store:main').get('adapter.url')
App.__container__.lookup('store:main').get('adapter.host')
DS.defaultStore.adapter.url
DS.defaultStore.adapter.host
Is there any way whatsoever (no matter how dirty/hacky/nauseating) to do this? Thanks!
EDIT: The correct answer is to initialize the adapter with a value you can access from elsewhere, like Kingpin2k pointed out below. I ended up creating an object with constant values and refer to it in both cases.
Upvotes: 1
Views: 506
Reputation: 47367
App.__container__.lookup('adapter:application').host
Example: http://emberjs.jsbin.com/OxIDiVU/978/edit
Honestly you should just define it as a property on your app, and use that property in your adapter as well, that way you can grab it off the app w/o having to do that.
App = Ember.Application.create({
applicationAdapterHost: '/foo'
});
App.ApplicationAdapter= DS.RESTAdapter.extend({
host:App.applicationAdapterHost
});
As you see, you can just grab it using App.applicationAdapterHost
whenever you want, easily
http://emberjs.jsbin.com/OxIDiVU/979/edit
Upvotes: 1