I'm very new to ember, and right now I simply want to call an api that generates random text, and have that text display on a page. The API and specific enpoint I'm using is "http://ift.tt/2ovGuPI" which returns a JSON response.
app/controllers/randomtext.js
import Ember from 'ember';
export default Ember.Controller.extend({
ajax: Ember.inject.service(),
actions: {
sendRequest() {
return this.get('ajax').request('http://ift.tt/2ovGuPI');
}
}
});
This is making the XHR request, and returning the correct JSON object. I can see it in the chrome developer tab.
This is my app/templates/randomtext.hbs
<h1>Random Text</h1>
<p>test</p><button >testing</button>
Pressing the button makes the xhr request, which is solid, but I have no idea how to get the text_out property of the json response, or display any part of it. How can I (simple as possible) make a GET request to an external api endpoint, and display the response on a page in my ember app?
Aucun commentaire:
Enregistrer un commentaire