dimanche 1 novembre 2015

Ember calling common code across objects

I am new to Ember and have a question regarding where to put common code. Consider a simple scenario. I have an AJAX request and I want to use the response in multiple places (say a route and in some controller OR 2 different controllers)

I have 2 questions;

  1. In Ember, can I access any controller (say X.js) from any other controller (say Y.js), by just using this.controllerFor(this.routeName)
  2. If the above is true, is that a better approach for common code (i.e. having a property in X controller to save the common API response) and then using it in another controller Y OR Should I use Ember Service for the common code and through dependency injection, consume the common code/API response ?

What is the correct way for this use case ?




Aucun commentaire:

Enregistrer un commentaire