My two routes have the same template and controller so my route want to use renderTemplate the same template and controller, like:
OrderRoute = Ember.Route.extend
model: (params)->
Product.findAll(params)
setupController: (controller, model)->
@controllerFor('product').set('model', model)
renderTemplate: ->
@render 'products',
controller: 'products'
actions:
queryParamsDidChange: ->
@refresh()
The controller:
ProductController = Ember.Controller.extend
queryParams: ['number']
number: null
The code look like is no problem, but when I use I found the query params
could not work.
jsbin: http://emberjs.jsbin.com/gegonemadu/1/edit
I could not google anything about this question.
I knew if I use OrderRoute
and OrderController
the route and controller have same name, all the think will be ok. But I my 2 route want to have the same template, just like:
/order
/other
2 route url use theproduct
template and controller
I am using {{partial}}
to this, just like: http://emberjs.jsbin.com/bifanateku/1/edit?html,js,console
This is can work, but I think if I can use renderTemplate
the code will be cleaner.
Maybe there is any better way to approach this problem?
For query params, the controller and the route should work together.
In your case, you're using the
order
route which expects query params from anorder
controller which you don't have.So you either define a different controller for the route, e. g.
or move the query params definition to the
order
controller and bind them to properties of theproduct
controller.This is a hairy set up, I believe you might be doing something wrong in the first place.
Update 1
You should not use controllers for that. Use components.
Ember is deprecating controllers and going to use only components. But for now, controllers are still necessary as entry points for your pages. The rest should be components!
Here's how you should do it:
Demo: http://emberjs.jsbin.com/xixeto/1/edit?html,js,output