Using JSONAPI with service


#1

Hello, can I use the jsonapi like that in a service?

//services/pics.js

import Ember from 'ember';

export default Ember.Service.extend({
    findAll: function(){
        return Ember.$.getJSON('http://api.donanimhaber.com/api/v1/site/NewsSite?pageIndex=0&pageSize=15');
    }

    });

I’m trying but I can’t see anything in the page. And no errors on chrome DevTools.

//components/image-list.hbs
{{#each model as |pic|}}
  <div>{{#link-to "pic" pic}}    
     <p class="info">{{pic.Title}}</p><br/>
     <img src={{pic.Image}} width="300">
  {{/link-to}}</div>
{{/each}}
{{yield}}

//templates/index.hbs
{{image-list model=model currentPos=currentPos }}
{{outlet}}


//routes/pic.js
import Ember from 'ember';
import DS from 'ember-data';


export default Ember.Route.extend({
    
    activate: function() {
        this._super(...arguments);
        window.scrollTo(0,0);
    },
    
    pics: Ember.inject.service(),
    model(params) {
        console.info(params, "Params");
        return this.get('pics').get('pics').find(function(item){
            if(Ember.isEqual(params.NewsUrl,item.NewsUrl)){
                return true;
            }
            else {
                return false;
            }
        });
} 
});

//routes/index.js
import Ember from 'ember';

export default Ember.Route.extend({
    pics: Ember.inject.service(),
    model() {
        console.log(this.get('pics').get('pics'));
        return this.get('pics').get('pics');
    }
    
});

#2

You never call findAll() from your pics-service.