{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/25784","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/25784/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/25784/comments","events_url":"https://api.github.com/repos/angular/angular/issues/25784/events","html_url":"https://github.com/angular/angular/issues/25784","id":356260487,"node_id":"MDU6SXNzdWUzNTYyNjA0ODc=","number":25784,"title":"Confusion on 'providedIn' for a specific NgModule","user":{"login":"DanielYKPan","id":5952855,"node_id":"MDQ6VXNlcjU5NTI4NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/5952855?v=4","gravatar_id":"","url":"https://api.github.com/users/DanielYKPan","html_url":"https://github.com/DanielYKPan","followers_url":"https://api.github.com/users/DanielYKPan/followers","following_url":"https://api.github.com/users/DanielYKPan/following{/other_user}","gists_url":"https://api.github.com/users/DanielYKPan/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielYKPan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielYKPan/subscriptions","organizations_url":"https://api.github.com/users/DanielYKPan/orgs","repos_url":"https://api.github.com/users/DanielYKPan/repos","events_url":"https://api.github.com/users/DanielYKPan/events{/privacy}","received_events_url":"https://api.github.com/users/DanielYKPan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-09-02T07:36:58Z","updated_at":"2018-09-02T08:28:37Z","closed_at":null,"author_association":"NONE","body":"<!--\r\nPLEASE HELP US PROCESS GITHUB ISSUES FASTER BY PROVIDING THE FOLLOWING INFORMATION.\r\n\r\nISSUES MISSING IMPORTANT INFORMATION MAY BE CLOSED WITHOUT INVESTIGATION.\r\n-->\r\n\r\n## I'm submitting a...\r\n<!-- Check one of the following options with \"x\" -->\r\n<pre><code>\r\n[ ] Regression (a behavior that used to work and stopped working in a new release)\r\n[ ] Bug report  <!-- Please search GitHub for a similar issue or PR before submitting -->\r\n[ ] Performance issue\r\n[ ] Feature request\r\n[ X  ] Documentation issue or request\r\n[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question\r\n[ ] Other... Please describe:\r\n</code></pre>\r\n\r\n## Current behavior\r\nThis is from the doc\r\n\r\n`The @Injectable() decorator has the providedIn metadata option, where you can specify the provider of the decorated service class with the root injector, or with the injector for a specific NgModule.`\r\n\r\n`Providing a service with the app's root injector is a typical case, and the CLI sets up this kind of a provider automatically for you when generating a new service. However, you might not always want to provide your service at the root level. You might, for instance, want users to explicitly opt-in to using the service.`\r\n\r\n`Instead of specifying the root injector, you can set providedIn to a specific NgModule.`\r\n\r\n`For example, in the following excerpt, the @Injectable() decorator configures a provider that is available in any injector that includes the HeroModule.`\r\n\r\nWhat I understand from the doc, when you use `providedIn: 'root'` in your service, you don't have to configure this service at the app module level. And the service is available anywhere the class is imported. \r\n\r\nBut if I use `providedIn: HeroModule`, I thought I didn't have to configure this service at the HeroModule level and I could use this service in HeroComponent (HeroComponent declared in HeroModule). This is not the case. And I still need to configure that service in HeroModule.\r\n\r\nSo What is this `providedIn: SpecificModule` for?\r\n\r\nhere is the [demo](https://stackblitz.com/edit/angular-1duwvx?file=src%2Fapp%2Fhero%2Fhero.service.ts)\r\n\r\n## Expected behavior\r\n<!-- Describe what the desired behavior would be. -->\r\n\r\n\r\n## Minimal reproduction of the problem with instructions\r\n<!--\r\nFor bug reports please provide the *STEPS TO REPRODUCE* and if possible a *MINIMAL DEMO* of the problem via\r\nhttps://stackblitz.com or similar (you can use this template as a starting point: https://stackblitz.com/fork/angular-gitter).\r\n-->\r\n\r\n## What is the motivation / use case for changing the behavior?\r\n<!-- Describe the motivation or the concrete use case. -->\r\n\r\n\r\n## Environment\r\n\r\n<pre><code>\r\nAngular version: 6.*.*\r\n<!-- Check whether this is still an issue in the most recent Angular version -->\r\n\r\nBrowser:\r\n- [ ] Chrome (desktop) version XX\r\n- [ ] Chrome (Android) version XX\r\n- [ ] Chrome (iOS) version XX\r\n- [ ] Firefox version XX\r\n- [ ] Safari (desktop) version XX\r\n- [ ] Safari (iOS) version XX\r\n- [ ] IE version XX\r\n- [ ] Edge version XX\r\n \r\nFor Tooling issues:\r\n- Node version: XX  <!-- run `node --version` -->\r\n- Platform:  <!-- Mac, Linux, Windows -->\r\n\r\nOthers:\r\n<!-- Anything else relevant?  Operating system version, IDE, package manager, HTTP server, ... -->\r\n</code></pre>\r\n"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/417913745","html_url":"https://github.com/angular/angular/issues/25784#issuecomment-417913745","issue_url":"https://api.github.com/repos/angular/angular/issues/25784","id":417913745,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzkxMzc0NQ==","user":{"login":"DanielYKPan","id":5952855,"node_id":"MDQ6VXNlcjU5NTI4NTU=","avatar_url":"https://avatars1.githubusercontent.com/u/5952855?v=4","gravatar_id":"","url":"https://api.github.com/users/DanielYKPan","html_url":"https://github.com/DanielYKPan","followers_url":"https://api.github.com/users/DanielYKPan/followers","following_url":"https://api.github.com/users/DanielYKPan/following{/other_user}","gists_url":"https://api.github.com/users/DanielYKPan/gists{/gist_id}","starred_url":"https://api.github.com/users/DanielYKPan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DanielYKPan/subscriptions","organizations_url":"https://api.github.com/users/DanielYKPan/orgs","repos_url":"https://api.github.com/users/DanielYKPan/repos","events_url":"https://api.github.com/users/DanielYKPan/events{/privacy}","received_events_url":"https://api.github.com/users/DanielYKPan/received_events","type":"User","site_admin":false},"created_at":"2018-09-02T08:28:37Z","updated_at":"2018-09-02T08:28:37Z","author_association":"NONE","body":"From what I understand from @trotyl comment\r\n\r\n`providedIn: SpecificModule would guarantee that the service can only be used when SpecificModule being imported, the same as configuring provider in its metadata.`\r\n\r\nIf I use  `providedIn: HeroModule` in `HeroService` (not declare in HeroModule) and import `HeroModule` in `AppModule`, I could inject the service in `AppComponent`.  But because `HeroService` not declare in `HeroModule`, `HeroComponent` could not inject `HeroService`."}}
{"actor":{"display_login":"DanielYKPan"}}