Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i get ApplicationController?

Tags:

ember.js

How can I get an ApplicationController inside my HomeController?

 HomeController=Ember.Controller.Extend({
   init:function {
        // Here I want to get My application controller. Is there any way to get??
   }

 })
like image 935
Bob Avatar asked Feb 19 '13 03:02

Bob


1 Answers

How can I get an ApplicationController inside my HomeController?

To specify dependencies (or needs) between controllers, use the needs property:

HomeController=Ember.Controller.Extend({
  needs: ['application']
})

Now Ember will make the application controller accessible from inside your HomeController as controllers.application. You can use it like any other HomeController, it is even accessible from your templates:

<!-- inside `home` template -->
{{controllers.application}}

See http://darthdeus.github.com/blog/2013/01/27/controllers-needs-explained/ for more detail on controller-needs.

BTW: It's pretty rare for an ember controller to use a custom init fx. Consider moving any initialization logic to setupController hook on the route instead.

like image 65
Mike Grassotti Avatar answered Oct 19 '22 17:10

Mike Grassotti