javascript - Access a route model from non nested route with Ember js -


i wondering appropriate way access route model different non nested route controller. if have routes set this: (this works however, not sure if proper)

app.router.map(function() {   this.route('admin');    this.route('page1'); } 

and page 1 route has model this:

app.page1model = {content:'content of simple model'};  app.page1route = ember.route.extend({    model(){       return app.page1model; }); 

then admin controller wants access page1 route, can this:

app.admincontroller = ember.controller.extend({     page1model:app.page1model,      stuff page1model..... }); 

ive tried use ember.inject.controller() works me when routes nested , want access parent controller child. there way use syntax want, or there better way im doing?

thanks

there's inherent problem you're asking for: when user on admin page, they're not on page1 page, there's no page1 context. questions might want ask:

  • what happens if user goes /admin having never gone /page1?
  • what happens if user goes /page1 /page2 /admin?

i can think of 2 ember-esque ways of doing want:

  1. a page1modelservice. here, create ember.service holds instance of page1model. inject service route:page1 , route:admin , let them each pull off instance. whether can change instance of model showing you.
  2. return page1model instance in model hook route:application. route sits above both route:page1 , route:admin, can both model follows:

    // route:application model() { return app.page1model.create(); }

    // route:page1 model() { return this.modelfor('application'); }


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -