0

I was trying to fully understand the previous answer of the question emberjs - how to mark active menu item using router infrastructure

In the answer I tried to simplify (without using a outlet navigation and without adding a second level routing under the root) but in my case the active link doesn't work ://

Here's a fiddle : http://jsfiddle.net/archange/Scqxw/

What I don't understand in the fiddle is why the "isActive: function()" is not updated after the set on the router... :/

So if someone passing by can explain me the reason. Big Thanks. And if someone has another solution for handling navigation menu (perhaps using bindAttr ?)

Thanks

Community
  • 1
  • 1
Archange
  • 397
  • 5
  • 21
  • Found a better solution [here](http://stackoverflow.com/questions/14412073/assigning-active-class-to-selected-list-item-in-emberjs). – Volox Apr 11 '13 at 11:07

1 Answers1

0

What is happening here is that when a template/view creates another view, it gives the newly created view access to it's controller. For example:

<script type="text/x-handlebars" data-template-name="application">
    {{view App.NavigationView}}
</script>

The controller of the navigation view is going to be the instance applicationController. This is expected behavior.

If you want to tell your newly created NavigationView to use another controller, just pass that in, like so:

{{view App.NavigationView controllerBinding="navigationController"}}

Please note that I wired these two controllers together in App.ready.

Here is your edited fiddle: http://jsfiddle.net/Scqxw/5/

Ryan
  • 3,594
  • 1
  • 24
  • 23
  • Thanks a lot. In the fiddle, I don't understand the reason for coupling the 2 controllers (app and nav). When I delete this link, I got an error `Target <(subclass of Em.View)> doesnt have action gotoAllTeachers`. I read again the doc. And I dound 'Ember sets the controller variable on the context (...) If a view has no controller property, inherits the controller from most recent view with one." Perfect I undertand my first mistake. From doc 'The controller singletons'll have their target property set to the application's router singleton'. Can you elaborate about wiring the controllers ? – Archange Sep 22 '12 at 11:50