jeudi 2 juin 2016

Using JSON Api URL EmberJS

I normally get data from a service I created, a hard-coded JSON. But I need to take the JSON from an URL.

This is my twiddle :

http://ift.tt/24kHC3i

How can I add a URL as a source instead of calling it from the service 'pics'? I tried something but got errors and couldn't do anything. I'm very new at this.

I tried

model() {
   return $.getJSON('/my-url');
}

But I get this error :

Mirage: Your Ember app tried to GET 'my URL', but there was no route defined to handle this request. Define a route that matches this path in your mirage/config.js file. Did you forget to add your namespace?

I totally had no idea about the error because I don't use mirage, I created it yeah but didn't use in any part of the project.

Then I tried :

import Ember from 'ember';

export default Ember.Route.extend({
    model() {
        this.get('my Json url', () => {
            return [];
        });
    }
});

Now chrome's devTool doesn't give any error but all I see is a blank-page. Is this all wrong or is it something about the .hbs files?

Any ideas?Thanks!




Aucun commentaire:

Enregistrer un commentaire