{"id":300,"date":"2022-08-30T14:59:03","date_gmt":"2022-08-30T14:59:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/09\/28\/ember-js-how-to-get-controller-in-needs-which-is-nested-controllername-record-and-share-programming-errors\/"},"modified":"2022-08-30T14:59:03","modified_gmt":"2022-08-30T14:59:03","slug":"ember-js-how-to-get-controller-in-needs-which-is-nested-controllername-record-and-share-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/ember-js-how-to-get-controller-in-needs-which-is-nested-controllername-record-and-share-programming-errors\/","title":{"rendered":"Ember.js How to get controller in needs which is nested controllerName-Record and share programming errors"},"content":{"rendered":"<p>I want to use <code>this.get('controllers.pack.query');<\/code> to get <code>App.PackQueryController<\/code> in <code>App.PackController<\/code>, but failed.<\/p>\n<p>I think the problem is Ember use <code>pack<\/code> not <code>pack.query<\/code> as <code>controllerName<\/code> when it tries to get the controller. Although I can get the controller by <code>this.controllerFor('pack.query')<\/code>, but Ember says it is deprecated, please use <code>needs<\/code> instead<\/p>\n<p>My router map likes below and I&#8217;ve defined <code>needs: ['pack.query']<\/code> in <code>App.PackController<\/code><\/p>\n<pre><code>App.Router.map(function () {\n    this.resource('pack', function () {\n        this.route('index', {path: '\/:pack_id'})\n        this.route('query');\n    });\n});\n\nApp.PackController = Ember.ObjectController.extend({\n    needs: ['pack.query'],\n    queryPack: function () {\n        var packQueryCtrller = this.get('controllers.pack.query');            \n\n        Ember.debug('packQueryCtrller: ' + packQueryCtrller);\n        \/\/DEBUG: packQueryCtrller: undefined\n\n        packQueryCtrller.queryPack(); \/\/faild packQuery is undefined\n    }\n});\n\nApp.PackQueryController = Ember.ArrayController.extend({\n    queryPack: function (queryKey) {\n        \/\/...do query pack\n    }\n});\n<\/code><\/pre>\n<ol>\n<li>\n<p>You should use camel case, not dot notation for this.<\/p>\n<p>Your pack controller should be<\/p>\n<pre><code> App.PackController = Ember.ObjectController.extend({\n   needs: ['packQuery'],\n   queryPack: function () {\n     var packQueryCtrller = this.get('controllers.packQuery');            \n\n     Ember.debug('packQueryCtrller: ' + packQueryCtrller);\n     \/\/DEBUG: packQueryCtrller: undefined\n\n     packQueryCtrller.queryPack(); \/\/faild packQuery is undefined\n   }\n});\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-09-28 06:10:24. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I want to use this.get(&#8216;controllers.pack.query&#8217;); to get App.PackQueryController in App.PackController, but failed. I think the problem is Ember use pack not pack.query as controllerName when it tries to get the controller. Although I can get the controller by this.controllerFor(&#8216;pack.query&#8217;), but Ember says it is deprecated, please use needs instead My router map likes below and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}