带有本地Firebase API的AngularFirestore是否可以在本地平台上工作?

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

因此,在我正在使用的应用程序中转换功能以使用AngularFire而不是Firebase的Web SDK时,我注意到您可以调用AngularFirestore的firestore属性,它允许您使用Firebase的本机API。

例如:

import { AngularFirestore, DocumentReference, DocumentSnapshot, QueryDocumentSnapshot } from '@angular/fire/firestore';
...
constructor(private dataService: DataService, private db: AngularFirestore
    ) { }
...

listenImages(): Function { //I call db.firestore here
        return this.db.firestore.collection('users').doc('bisonlife').collection('bisonlife').doc(this.dataService.uid.value)
            .collection('images').orderBy("dateAdded", "desc").onSnapshot(querySnapshot => {
                let messages = [];
                querySnapshot.forEach(thing => {
                    messages.push({
                        ...thing.data()
                    });
                });
                this.zone.run(() => {
                    this.uploadedPhotos = messages;
                });
            });
    }

不引发错误。即使它使用Firebase的本机API而不是AngularFirestore,它仍然可以在常规浏览器上运行。

我目前正在使用Ionic。我的问题是,如果我以这种方式调用Firebase的本机API,如果我构建到iOS和Android,AngularFire是否仍可以将这些功能包装到本机代码中?如果是这样的话,肯定会为我节省很多时间。我将Web SDK用于要放在移动设备上的应用程序时犯了一个错误,因此我目前正在尝试将所有与Firestore相关的功能转换为AngularFirestore可以使用的功能。预先谢谢!

firebase ionic-framework google-cloud-firestore ionic4 angularfire
1个回答
0
投票
cordova plugin add <cordova-plugin>

然后,该插件将调用本机代码。但这种情况并非如此。在ionic中使用firebase web sdk应该不会有任何问题。 angularfire已在其源代码中使用它。

使用angularfire的全部目的是使将数据绑定到模板更容易。因此,最好在使用angular的离子项目中使用它。(但这与本机代码调用无关。 )

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