Is it possible to use Angular 1.x service inside Angular 2+ service? I am getting the following error when doing so:
Trying to get the AngularJS injector before it being set.
However, it works if I use Angular 1 service inside Angular 2 component (instead of service).
App.Module.ts:
function getA1Service(i:any) { return i.get('a1Service') }
@NgModule({
declarations: [...],
imports: [...],
entryComponents: [...],
providers: [...,
A2Service,
{ provide: 'a1Service', useFactory: getA1Service, deps: '$injector']},
],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(private upgrade: UpgradeModule) {
}
ngDoBootstrap() {
}
}
A2Service.ts:
export class A2Service {
constructor(private http:HttpClient, @Inject('a1Service') private a1Service) {}
getData() : Observable<data> {
return this.http.get<data>(...);
}
}
Main.ts:
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.documentElement, ['app']);
})
.catch(err => console.log(err));