angular: Angular 1 service not able to use in Angular2

I have a LoginInfoService implemented in ng1.

To use this in hybrid angular application as per documentation i have done the following -

  1. created app module
import { NgModule, ElementRef}      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }   from './app.component';
import { UpgradeModule } from '@angular/upgrade/static';
@NgModule({
    imports: [BrowserModule,
        HttpModule,
        JsonpModule,
        UpgradeModule
    ],
    declarations: [...    ],
    providers: [      
        LoginInfoService,
        { provide: 'LoginInfoService', useFactory: (i: any) => i.get('LoginInfoService'), deps: ['$injector'] },
    ],
    entryComponents:[...   ]
    

})
export class AppModule {
    ngDoBootstrap() { /* this is a placeholder to stop the boostrapper from complaining */
    }
}
  1. created a wrapper ng2 service as below -
import {Injectable, Inject} from "@angular/core";

@Injectable()
export class LoginInfoService {

    constructor( @Inject("LoginInfoService") public loginInfoService: LoginInfoService) {
        return loginInfoService;
    }
    isDirectvInFocus() {
        return this.loginInfoService.isDirectvInFocus();

    }
    isWirelessInFocus() {
        return this.loginInfoService.isWirelessInFocus();

    }
    getAccountInFocus() {
        return this.loginInfoService.getAccountInFocus();
    }
    getLoginType() {
        return this.loginInfoService.getLoginType();
    }
}
  1. in main ts
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
  const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
  upgrade.bootstrap(document.documentElement, ['myApp']);//this is angular1 module
});

And getting the following error -

zone.js:405 Unhandled Promise rejection: No provider for LoginInfoService! ; Zone: <root> ; Task: Promise.then ; Value: Error: No provider for LoginInfoService!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 18 (7 by maintainers)

Most upvoted comments

please check now. I have used correct token ‘LoginInfoService’ now.

This is bug as the same service was working perfectly fine using upgradeAdapter. As soon as i switeched to upgradeModule from upgradeAdapter, this issue came. I relied on added four API - UpgradeModule, UpgradeComponent, downgradeInjectables,downgradeComponent. I am blocked due to this issue.

Hello, we reviewed this issue and determined that it doesn’t fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag angular.

If you are wondering why we don’t resolve support issues via the issue tracker, please check out this explanation.

what do you mean eric ? is it not a valid query ?