0

I am creating application using angular and calling api call inside the ngdobootrap method. I am getting error while injecting the service inside bootstrap:

export class AppModule {
    constructor(private upgrade: UpgradeModule, private router: Router, private location: Location,private services : someservice) { }
    ngDoBootstrap(moduleRef) {
      this.getdata()
    }
    getdata() {
      this.services.data().subscribe((res: any) => {
       console.log(res)
      }, error => {
       
      })
    }

Error:

zone.js:682 Unhandled Promise rejection: Trying to get the AngularJS injector before it being set. ; Zone: <root> ; Task: Promise.then ; Value: Error: Trying to get the AngularJS injector before it being set.
    at injectorFactory (vendor.js:148805:15)
Karan
  • 1,048
  • 2
  • 20
  • 38

1 Answers1

0

Add the forwardRef to the service in the constructor,

@Inject(forwardRef(() => 'someservice')) private services : someservice

There is more detail here

Makhele Sabata
  • 582
  • 6
  • 16