-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inject() must be called from an injection context such as a constructor in AngularFirestoreDoc after upgrading to Angular v19 #3621
Comments
This issue does not seem to follow the issue template. Make sure you provide all the required information. |
Hi, I have exactly the same issue. Thank you ! |
I am having the same issue with version 19.0.0, it worked with the rc.0 release candidate of version 19 before though. I have confirmed that version 19.0.0-rc.0 is the latest version without this issue, is there some new way to implement this that is not documented or is this a real issue? |
I believe that if you switch from the namespace syntax to the modular style that will solve the issue. https://firebase.google.com/docs/web/modular-upgrade |
I hope there is still another solution, since my project is huge with multiple different services |
You could wrap the modular methods in an Angular Service. Still a large change, but mostly just renaming things hopefully. I can describe more if interested. The only other solution is to wrap every Firebase method in an injection context. Or, stick with older versions. |
Would appreciate it if you could provide more information! |
Something like: import {
EnvironmentInjector,
inject,
Injectable,
runInInjectionContext,
} from '@angular/core';
import { doc, Firestore } from '@angular/fire/firestore';
import type { DocumentReference } from '@angular/fire/firestore';
@Injectable({ providedIn: 'root' })
export class AngularFirestoreService {
private readonly _firestore: Firestore = inject(Firestore);
private readonly _injector: EnvironmentInjector = inject(EnvironmentInjector);
/**
* Note that the doc method could accept a CollectionReference or DocumentReference in addition to
* Firestore.
*/
public doc(path: string, ...pathSegments: string[]): DocumentReference {
return runInInjectionContext(
this._injector,
(): DocumentReference => doc(this._firestore, path, ...pathSegments),
);
}
} But note that I didn't test this code, it is off the cuff at 07:30 in the morning for me so it might be terrible. |
I recently upgraded all dependencies to Angular v19 (from v18). I was previously on Angular v18 where everything worked fine. However, now, my whole console is spammed with the following error:
However, my auth service at line 38:14 only has the following code:
.doc<User>(`users/${user.uid}`)
The whole constructor looks like this (it is a angular service class)
But I dont really know, why it does not work anymore in angular 19.
My package dependencies:
I also tried to set "preserveSymlinks": false, in angular.json however, the issue still persists.
The text was updated successfully, but these errors were encountered: