dimanche 7 février 2016

Access a route model from non nested route with Ember js

I am wondering the appropriate way to access a route model from a different non nested route controller. If I have my routes set up like this: (this works however, not sure if its proper)

App.Router.map(function() {
  this.route('admin'); 
  this.route('page1');
}

And the Page 1 route has a model like this:

App.page1Model = {content:'Content of simple model'};

App.Page1Route = Ember.Route.extend({
   model(){
      return App.page1Model;
});

Then the admin controller wants to access the page1 route, I can only do it like this:

App.AdminController = Ember.Controller.extend({
    page1Model:App.page1Model,

    Now do stuff with page1Model.....
});

Ive tried to use Ember.inject.controller() however that only works for me when my routes are nested and I want to access Parent controller from child. Is there a way to use that syntax to get what I want, or is there a better way than what im doing?

Thanks

Aucun commentaire:

Enregistrer un commentaire