Angular 16:您的 AppModule 中尚未提供 AngularFireModule (这可以手动或使用 ProvideFirebaseApp 隐式完成)

问题描述 投票:0回答:1

**版本信息: @角度/火7.6.1 @角度/常见”:16.0.0

我收到的错误: enter image description here

我试图在我的 Angular 项目中实现单元测试,我已经实现了 Angular/Fire,代码运行完美,但在单元测试时它要求 AngularFireModule(在新版本中已被弃用):

我的认证服务:

import { Injectable } from '@angular/core';
import { from, Observable } from 'rxjs';
import {
  Auth,
  signInWithEmailAndPassword,
  authState,
  createUserWithEmailAndPassword,
  UserCredential,
} from '@angular/fire/auth';

@Injectable({
  providedIn: 'root',
})
export class AuthService {
  currentUser$ = authState(this.auth);
  constructor(private auth: Auth) {}

  signUp(email: string, password: string): Observable<UserCredential> {
    return from(createUserWithEmailAndPassword(this.auth, email, password));
  }

  login(email: any, password: any): Observable<any> {
    return from(signInWithEmailAndPassword(this.auth, email, password));
  }

  logout(): Observable<any> {
    return from(this.auth.signOut());
  }
}
angular firebase angularfire
1个回答
0
投票

您有以下情况吗?

import { provideFirebaseApp, initializeApp, getApp } from '@angular/fire/app';
import { getFirestore, provideFirestore } from '@angular/fire/firestore';

imports: [

    provideFirebaseApp(() => initializeApp(environment.firebase)),
    provideFirestore(() => getFirestore(getApp()))

...
]

基于文档: https://github.com/angular/angularfire/tree/master

© www.soinside.com 2019 - 2024. All rights reserved.