Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Lazy-load the Firestore with standalone components

未关闭
#3,584 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
angular, firebase, typescript
领域
database, frontend

调研方向

首先阅读独立组件 get-firestore.ts 以及报告中展示的 provideFirestore/getFirestore 入口点。使用所列出的 Angular、Firebase 和 AngularFire 版本复现运行时错误,然后记录或实现受支持的延迟加载路径,并验证 Firestore 未在应用配置中初始化。

由索引模型根据 Issue 内容生成。

描述

Hi, is there a way to lazy-load the Firestore?

I'm using it only in a lazy-loaded component, so I would like to avoid providing it in the app config with
provideFirestore(() => getFirestore())

I followed this example: https://github.com/angular/angularfire/blob/main/samples/advanced/src/app/firestore/firestore.component.ts

I have a get-firestore.ts with this content:

import { getFirestore } from '@angular/fire/firestore';
export const firestore = getFirestore();

and I try to lazy-load it like this:

constructor() {
  this.initFirestore();
}

private async initFirestore() {
  const { firestore } = await import('./get-firestore');
  this.firestore = firestore;
}

But I get this error at run-time:

Error: Either AngularFireModule has not been provided in your AppModule (this can be done manually or implictly using
provideFirebaseApp) or you're calling an AngularFire method outside of an NgModule (which is not supported).

Even if I add the AngularFireModule to the component's imports, it doesn't change.

So, what's the right way to lazy-load the FIrestore, with standalone components?

Version info

Angular: 19.0.0

Firebase: 10.12.0

AngularFire: 18.0.1

主要语言
TypeScript
星标
7.8k
派生
2.2k
平均合并
3 天 6 小时
30 天内合并 PR
5

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angularfire 的其他 Issue

查看 angular/angularfire 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。