Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4828

Why the Ember Components does not fetch the data by themself?

$
0
0

@TatzyXY wrote:

Hi,

lets say I have a user component and I want to display the username on every page.
So I need the userdata on every page but if I do this over the route-models I have to fetch the data on all pages. Again and again. On every url I have to create then a route file and paste that user fetch logic in that file.
This would be a copy paste disaster.

What would be a good practice in Ember to solve this issue?

I started yesterday with Ember.js please dont throw with stones at me when this is a very stupid question :wink:


Edit: This looks good to me but I think its not the best practice. Too bad because I think in some cases this is the better concept.Code is from StackOverflow.

import Ember from 'ember';

export default Ember.Component.extend({

  store: Ember.inject.service(),

  init() {
    this.initialize();
    this._super();
  },

  initialize() {
    this.todos().then((data) => {
      this.set('todoEntries', data);
    });
  },

  todos() {
    const store = this.get('store');
    return store.findAll('todo');
  },
});

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4828

Trending Articles