Just been watching the Ember Peepcode video. One thing it has hammered home to me is that Controllers are singletons, so a single instance of each Controller is created at runtime and the controller's data property is swapped in/out as needed.
But what happens when you need multiple versions of the same controller on screen and active at the same time. What happens if I have multiple example.handlebars
templates, each of which needs to be backed by its own version of ExampleController
on screen simultaneously?
How does Ember handle this situation?
There are several ways to handle that (mentioned in my previous answer).
Method 1:
{{render}}
with a model (needs latest Ember.js build):
{{render "example" example1}}
{{render "example" example2}}
Method 2:
{{control}}
has been removed from Ember >= 1.0.{{control}}
(it is still buggy so avoid if you can)
{{control "example"}}
But first you need to enable the flag: ENV.EXPERIMENTAL_CONTROL_HELPER = true
before loading ember.js file.
There's also a bug which you'll need to fix by doing:
App.register('controller:example', App.ExampleController, {singleton: false }
Method 3:
Using {{each}}
with itemController
.
{{#each controller itemController="example"}}
{{view "example"}}
{{/each}}
Each of these will create a new separate instance every time.
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