{"action":"created","issue":{"url":"https://api.github.com/repos/emberjs/ember.js/issues/12602","repository_url":"https://api.github.com/repos/emberjs/ember.js","labels_url":"https://api.github.com/repos/emberjs/ember.js/issues/12602/labels{/name}","comments_url":"https://api.github.com/repos/emberjs/ember.js/issues/12602/comments","events_url":"https://api.github.com/repos/emberjs/ember.js/issues/12602/events","html_url":"https://github.com/emberjs/ember.js/issues/12602","id":116851903,"number":12602,"title":"Factories cannot be injected into template-only components?","user":{"login":"grantovich","id":394835,"avatar_url":"https://avatars.githubusercontent.com/u/394835?v=3","gravatar_id":"","url":"https://api.github.com/users/grantovich","html_url":"https://github.com/grantovich","followers_url":"https://api.github.com/users/grantovich/followers","following_url":"https://api.github.com/users/grantovich/following{/other_user}","gists_url":"https://api.github.com/users/grantovich/gists{/gist_id}","starred_url":"https://api.github.com/users/grantovich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grantovich/subscriptions","organizations_url":"https://api.github.com/users/grantovich/orgs","repos_url":"https://api.github.com/users/grantovich/repos","events_url":"https://api.github.com/users/grantovich/events{/privacy}","received_events_url":"https://api.github.com/users/grantovich/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-11-13T21:05:29Z","updated_at":"2016-04-20T13:34:26Z","closed_at":null,"body":"Using Ember 2.1, suppose I want to inject a service into all components:\r\n\r\n```js\r\n// app/initializers/my-thing.js\r\nexport function initialize(application) {\r\n  application.inject('component', 'myThing', 'service:my-thing');\r\n}\r\n\r\nexport default {\r\n  name: 'my-thing',\r\n  initialize: initialize\r\n};\r\n```\r\n\r\nIf I place a reference to `{{myThing}}` in `app/templates/components/my-component.hbs`, and I have no corresponding `app/components/my-component.js`, it comes out `undefined`. If I create that component JS file (with no content except `export default Ember.Component.extend()`), the reference in the template starts working. This is inconvenient, since I have many components that need this injected reference and would otherwise be template-only.\r\n\r\nI find this strange, because the corresponding controller-based scenario works just fine. If I have only `app/templates/index.hbs` without any index controller defined, injecting the service into all controllers is sufficient to make it accessible in the template. Why do components work differently?"},"comment":{"url":"https://api.github.com/repos/emberjs/ember.js/issues/comments/212425710","html_url":"https://github.com/emberjs/ember.js/issues/12602#issuecomment-212425710","issue_url":"https://api.github.com/repos/emberjs/ember.js/issues/12602","id":212425710,"user":{"login":"rwjblue","id":12637,"avatar_url":"https://avatars.githubusercontent.com/u/12637?v=3","gravatar_id":"","url":"https://api.github.com/users/rwjblue","html_url":"https://github.com/rwjblue","followers_url":"https://api.github.com/users/rwjblue/followers","following_url":"https://api.github.com/users/rwjblue/following{/other_user}","gists_url":"https://api.github.com/users/rwjblue/gists{/gist_id}","starred_url":"https://api.github.com/users/rwjblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwjblue/subscriptions","organizations_url":"https://api.github.com/users/rwjblue/orgs","repos_url":"https://api.github.com/users/rwjblue/repos","events_url":"https://api.github.com/users/rwjblue/events{/privacy}","received_events_url":"https://api.github.com/users/rwjblue/received_events","type":"User","site_admin":false},"created_at":"2016-04-20T13:34:26Z","updated_at":"2016-04-20T13:34:26Z","body":"Another good solution is a helper that returns the service:\r\n\r\nFor example, with the following helper:\r\n\r\n```js\r\n// app/helpers/service.js\r\nimport getOwner from 'ember-getowner-polyfill';\r\n\r\nexport default Ember.Helper.extend({\r\n  compute([serviceName]) {\r\n    let owner = getOwner(this);\r\n    return owner.lookup(`service:${serviceName}`);\r\n  }\r\n})\r\n```\r\n\r\nYou could do this in the template:\r\n\r\n```hbs\r\n{{#with (service 'fooBarBaz') as |foo|}}\r\n  {{! use foo here}}\r\n{{/with}}\r\n```\r\n\r\nYou could also do:\r\n\r\n```hbs\r\n{{some-other-component derp=(service 'something')}}\r\n```\r\n"}}