4

I currently have a project where I have an angular workspace in which I have created an angular web app. Now I also needed an app and created an angular ionic app. I wanted to reuse my existing authentication service which uses AngularFireauth and AngularFirestore so I created a library and extracted the service. When using the service from the library in the angular web app everything works fine. But trying to inject the service in a page from the ionic app I get the error inject() must be called from an injection context. When moving the service from the library to the ionic app and just using it from there it works.

Ionic v.5.0.5

Angular v.9.0.6

Maybe someone has an idea.

Thanks for your help!

Vala Khosravi
  • 2,352
  • 3
  • 22
  • 49
Patrick
  • 349
  • 1
  • 7
  • 15

2 Answers2

15

Just after asking the question i somehow found the answer at the bottom of a post which suggested adding

"paths": { "@angular/*": [ "./node_modules/@angular/*" ] }

to the tsconfig.app.json under the compilerOptions of the app where i was trying to inject the service.

Patrick
  • 349
  • 1
  • 7
  • 15
6

In my case, two solutions worked for me:

  1. In your application, add to the angular.json file the property preserveSymlinks: true in projects.$name.architect.build.options.

  2. @Patrick Solution (I don't recommend):

    "paths": { "@angular/*": [ "./node_modules/@angular/*" ] }
    

The most likely explanation is two different copies of @angular/core were bundled to the app.:

titusfx
  • 1,896
  • 27
  • 36
  • Exactly: The most likely explanation is two different copies of @angular/core were bundled to the app. This was the issue in my case. – Hafnernuss Nov 16 '21 at 08:53