我已经设法让 @angular/fire 在 Angular 独立应用程序中工作,但我正在尝试像过去一样打开离线功能,现在我看到它已enableIndexedDbPersistence被标记为已弃用。它建议如下:
该功能将在未来的主要版本中删除。相反,将 FirestoreSettings.cache 设置为 IndexedDbLocalCache 的实例以打开 IndexedDb 缓存。当 FirestoreSettings.cache 已指定时调用此函数将引发异常。
我已经阅读了通常可以很好地解释如何使用 @angular/fire 的文档(https://firebase.google.com/docs/firestore/manage-data/enable-offline),但我没有看到关于做什么的任何明显指示。文档显示了如何使用传递到调用中的选项参数initializeFirestore,但 Angular 应用程序似乎没有在外部使用此方法(从开发人员的角度来看)。
我目前拥有的是以下内容:
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideAnimations(),
provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000',
}),
importProvidersFrom(
provideFirebaseApp(() =>
initializeApp({
// ... my info
})
),
provideAuth(() => getAuth()),
provideFirestore(() => {
const firestore = getFirestore();
enableIndexedDbPersistence(firestore); // Marked as deprecated :(
return firestore;
}),
provideStorage(() => getStorage())
),
],
};
Run Code Online (Sandbox Code Playgroud)