{"action":"created","issue":{"url":"https://api.github.com/repos/angular/angular/issues/14760","repository_url":"https://api.github.com/repos/angular/angular","labels_url":"https://api.github.com/repos/angular/angular/issues/14760/labels{/name}","comments_url":"https://api.github.com/repos/angular/angular/issues/14760/comments","events_url":"https://api.github.com/repos/angular/angular/issues/14760/events","html_url":"https://github.com/angular/angular/issues/14760","id":210468968,"number":14760,"title":"$Injector is missing when tried to use upgraded service is ng2 component.","user":{"login":"vasuneet","id":3884434,"avatar_url":"https://avatars1.githubusercontent.com/u/3884434?v=4","gravatar_id":"","url":"https://api.github.com/users/vasuneet","html_url":"https://github.com/vasuneet","followers_url":"https://api.github.com/users/vasuneet/followers","following_url":"https://api.github.com/users/vasuneet/following{/other_user}","gists_url":"https://api.github.com/users/vasuneet/gists{/gist_id}","starred_url":"https://api.github.com/users/vasuneet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vasuneet/subscriptions","organizations_url":"https://api.github.com/users/vasuneet/orgs","repos_url":"https://api.github.com/users/vasuneet/repos","events_url":"https://api.github.com/users/vasuneet/events{/privacy}","received_events_url":"https://api.github.com/users/vasuneet/received_events","type":"User","site_admin":false},"labels":[{"id":245057144,"url":"https://api.github.com/repos/angular/angular/labels/comp:%20upgrade/dynamic","name":"comp: upgrade/dynamic","color":"c7def8","default":false},{"id":130606843,"url":"https://api.github.com/repos/angular/angular/labels/type:%20bug","name":"type: bug","color":"EEEEEE","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-02-27T12:22:04Z","updated_at":"2017-12-15T11:13:43Z","closed_at":"2017-12-15T11:13:43Z","author_association":"NONE","body":"I have a LoginInfoService implemented in ng1.\r\n\r\nTo use this in hybrid angular application as per documentation i have done the following -\r\n\r\n1. Created ajs-upgraded-providers for LoginInfoServiceProvider - \r\n    ```ts\r\n    import { LoginInfoService } from './ng2/login/services/LoginInfoService';\r\n\r\n    export function LoginInfoServiceFactory(i: any) {\r\n        return i.get('LoginInfoService');\r\n    }\r\n    export const LoginInfoServiceProvider = {\r\n        provide: LoginInfoService,\r\n        useFactory: LoginInfoServiceFactory,\r\n        deps: ['$injector']\r\n    };\r\n    ```\r\n\r\n2. created app module\r\n    ```ts\r\n    import { NgModule, ElementRef}      from '@angular/core';\r\n    import { BrowserModule } from '@angular/platform-browser';\r\n    import { AppComponent }   from './app.component';\r\n    import { UpgradeModule } from '@angular/upgrade/static';\r\n    @NgModule({\r\n        imports: [\r\n            BrowserModule,\r\n            HttpModule,\r\n            JsonpModule,\r\n            UpgradeModule\r\n        ],\r\n        declarations: [...],\r\n        providers: [      \r\n            LoginInfoServiceProvider\r\n        ],\r\n        entryComponents:[AppComponent ]\r\n    })\r\n    export class AppModule {\r\n        ngDoBootstrap() { /* this is a placeholder to stop the boostrapper from complaining */ }\r\n    }\r\n    ```\r\n\r\n3. created a wrapper ng2 service as below -\r\n    ```ts\r\n    import {Injectable, Inject} from \"@angular/core\";\r\n\r\n    @Injectable()\r\n    export class LoginInfoService {\r\n        constructor( @Inject(\"LoginInfoService\") public loginInfoService: LoginInfoService) {\r\n            return loginInfoService;\r\n        }\r\n\r\n        isDirectvInFocus() {\r\n            return this.loginInfoService.isDirectvInFocus();\r\n        }\r\n\r\n        isWirelessInFocus() {\r\n            return this.loginInfoService.isWirelessInFocus();\r\n        }\r\n\r\n        getAccountInFocus() {\r\n            return this.loginInfoService.getAccountInFocus();\r\n        }\r\n\r\n        getLoginType() {\r\n            return this.loginInfoService.getLoginType();\r\n        }\r\n    }\r\n    ```\r\n\r\n4. in main ts\r\n    ```ts\r\n    platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {\r\n        const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;\r\n        upgrade.bootstrap(document.documentElement, ['myApp']);//this is angular1 module\r\n    });\r\n    ```\r\n\r\nAnd getting the following error -\r\n\r\n```\r\nzone.js:344 Unhandled Promise rejection: Cannot read property 'get' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'get' of undefined(…) TypeError: Cannot read property 'get' of undefined\r\n    at LoginInfoServiceFactory (http://localhost:3000/ajs-upgraded-providers.js:5:17)\r\n```"},"comment":{"url":"https://api.github.com/repos/angular/angular/issues/comments/351980470","html_url":"https://github.com/angular/angular/issues/14760#issuecomment-351980470","issue_url":"https://api.github.com/repos/angular/angular/issues/14760","id":351980470,"user":{"login":"gkalpak","id":8604205,"avatar_url":"https://avatars2.githubusercontent.com/u/8604205?v=4","gravatar_id":"","url":"https://api.github.com/users/gkalpak","html_url":"https://github.com/gkalpak","followers_url":"https://api.github.com/users/gkalpak/followers","following_url":"https://api.github.com/users/gkalpak/following{/other_user}","gists_url":"https://api.github.com/users/gkalpak/gists{/gist_id}","starred_url":"https://api.github.com/users/gkalpak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gkalpak/subscriptions","organizations_url":"https://api.github.com/users/gkalpak/orgs","repos_url":"https://api.github.com/users/gkalpak/repos","events_url":"https://api.github.com/users/gkalpak/events{/privacy}","received_events_url":"https://api.github.com/users/gkalpak/received_events","type":"User","site_admin":false},"created_at":"2017-12-15T11:13:43Z","updated_at":"2017-12-15T11:13:43Z","author_association":"MEMBER","body":"This is just wrong usage. You are trying to `@Inject('LoginInfoService')`, but there is no Angular provider identified by that token (the string `LoginInfoService`).\r\n\r\nThere is no need to wrap the service. Just drop the `LoginInfoService` class (implemented in Angular) and rely on the `LoginInfoServiceProvider` for providing the `LoginInfoService` to the Angular part of the app."}}
{"actor":{"display_login":"gkalpak"}}