Many things have changed with the new Ember.js router. I've migrated most things, but there's one use case that I can't seem to fit into the Ember.js way of doing things.
Say I have an app with some controllers. Some of these controllers belong to the routes in my App.Router
and some of them don't, namely my I18nController
. This is a non-router controller that makes sure to translate stuff all over the app via a Handlebars helper.
I also have an App.UserController
that has an App.User
record as its content
.
Previously, I was able to setup a binding between App.I18nController
and App.UserController
via the rather ugly localeBinding: 'App.router.userController.content.locale'
, allowing me to read the user's locale at any time when localizing.
However, with the new router, this is no longer possible.
My question is: how should I setup this binding using the new router?
With the new router there are a couple of different strategies for setting up bindings (dependencies) between controllers. One option is to set this.controllerFor
in your setupControllers callback in your route defition. Another is to register dependencies for inject prior to app creation. These and a couple of other options are discussed in this github issue. If you follow that thread you'll find code examples for these various strategies. It doesn't seem like a real convention has been established yet but I like the calls like App.container.injection("controller", "settings", "controller:settingsController")
approach because it is very declarative and clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With