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:
- a page1modelservice. here, create
ember.service
holds instance ofpage1model
. inject serviceroute:page1
,route:admin
, let them each pull off instance. whether can change instance of model showing you. return
page1model
instance inmodel
hookroute:application
. route sits above bothroute:page1
,route:admin
, can both model follows:// route:application model() { return app.page1model.create(); }
// route:page1 model() { return this.modelfor('application'); }
Comments
Post a Comment