Error: inject() must be called from an injection context
See original GitHub issueI am using @angular/cli@8.2.4
, but the error happens as well in 8.0.1
(for me)
To reproduce it, I just had to follow the steps in “Getting started” section.
After ng serve
, the build runs well but the console outputs :
Error: CollectionService requires AngularFirestore
But I am injecting AngularFirestoreModule
in AppModule, and I imported it in the service as well. My code does not differ from documentation, that is :
import { Injectable } from '@angular/core';
import { MovieStore, MovieState } from './movie.store';
import { AngularFirestore } from '@angular/fire/firestore';
import { CollectionConfig, CollectionService } from 'akita-ng-fire';
@Injectable({ providedIn: 'root' })
@CollectionConfig({ path: 'movies' })
export class MovieService extends CollectionService<MovieState> {
constructor(store: MovieStore) {
super(store);
}
}
I tried to inject AngularFirestore
service in constructor too, but it was not better.
So, I installed the project from source to output the real error and it was
Error: inject() must be called from an injection context
Seems linked to this - still open - angular issue, but the proposed workaround does not work for me. I am having a hard time trying to understand this error.
EDIT: Here is how to easily reproduce it:
- ng new angular-test
- cd angular-test
- ng add @angular/fire
- ng add @datorama/akita
- ng g feature movies/movies
- (inject moviesService into app component constructor)
- ng serve
If necessary, I will add a stackblitz soon to reproduce this.
I was trying to do something similar to akita-ng-fire, but your project is way better. I would be glad to use it in our application, since you added atomic writings. This will be an essential tool for angularfire developers. Thumbs up 👍
NB: would be interesting to output the real error (or make a logger debug level) in addition to your error logs
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
I finally found out what happened, that was dumb. When using linked local library, we always put the library in an external project. But we found out in this issue that it is normally not working (don’t know why it worked until here with our other old librairies), and so the
inject()
method was not working.I just put the npm linked librairies into the
project/
directory and it’s working like a charm now, sorry for having bothered you. I can send PR toakita-ng-fire
now 😃@loicmarie haha, I had the same issue, thanks for your investigation. I just wasted about 4 hours to find the cause of issue…