AngularFireModule from @angular/fire/compat not providing the database appropriately.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 7.8k
- Forks
- 2.2k
- Ø Merge
- 22 Std. 28 Min.
- Gemergte PRs (30 T.)
- 6
Beschreibung
So I've been facing an issue for the past couple of days where whenever I try to use the **AngularFireDatabase** database to read or write to my Firebase database my console gives me the error:
`No provider found for Database2. Source: Standalone[_Homecomponent].`
I'm currently running Angular 20.0 as AngularFire 21.0 is yet to be fully fleshed out.
My dummy service to test the data looks like this below:
`import { Injectable } from '@angular/core';`
`import { AngularFireDatabase } from '@angular/fire/compat/database';`
`@Injectable({`
` providedIn: 'root'`
`})`
`export class Postingservice {`
`constructor(private afDb:AngularFireDatabase){}`
`viewPosts(){`
`return this.afDb.list("/posts").valueChanges();`
`}`
`}`
I've both tried instantiating the afDb in the constructor and using the inject() function and neither have worked to any avail.
Here also is my app.config.ts:
`import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';`
`import { provideRouter } from '@angular/router';`
`import { initializeApp, provideFirebaseApp } from '@angular/fire/app';`
`import { getDatabase, provideDatabase } from '@angular/fire/database';`
`import { routes } from './app.routes';`
`export const appConfig: ApplicationConfig = {`
` providers: [`
`provideBrowserGlobalErrorListeners(),`
`provideZoneChangeDetection({ eventCoalescing: true }),`
` provideRouter(routes), `
`provideFirebaseApp(() => `
` initializeApp({`
`// FIREBASE CONFIG DATA`
`})),`
`provideDatabase(() => getDatabase()),`
`]`
`};`
I've even provided the provideDatabase() function even as it's not necessary for the AngularFireDatabase as a provider and likewise it's been to no avail...
And my application is bootstrapping correctly as it runs just fine until I create an instance of the afDb database in a component where I then get the above stated error. Kindly help.
Beitragsleitfaden
Rechercherichtung
Beginne damit, den Injection-Fehler mit der gezeigten app.config.ts und dem Postingservice zu reproduzieren, der AngularFireDatabase injiziert. Lies das Compat-Datenbank-Setup neben dem Setup des Standalone-Providers und überprüfe anschließend, dass AngularFireDatabase injiziert werden kann und viewPosts() /posts liest, ohne dass der Fehler No provider found auftritt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- angular, typescript
- Bereich
- database
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 42/100