Firestore:snapshotChanges 不是函数

Firestore: snapshotChanges is not a function

关于 this post,我遇到了一个问题 snapshotChanges is not a function:

TypeError: db.collection(...).snapshotChanges is not a function
    at new <anonymous> (index.js:139)
    at Object.instantiate (angular.js:5156)
    at angular.js:11719
    at Object.link (angular-route.js:1251)
    at angular.js:1388
    at Ba (angular.js:11266)
    at p (angular.js:10585)
    at g (angular.js:9832)
    at angular.js:9697
    at angular.js:10111 "<ng-view autoscroll="true" class="ng-scope">"

下面是我的代码: (请注意,有或没有 pipe() 也会遇到同样的错误。)

var db = firebase.firestore();

        $scope.accounts = db.collection("Accounts").snapshotChanges().pipe(map(actions => {
            return actions.map(a => {
                const data = a.payload.doc.data();
                const id = a.payload.doc.id;
                return { id, ...data };
            });
        }));

在我的 SPA index.html 上,我定义了以下引用:

<script defer src="/__/firebase/6.4.1/firebase-app.js"></script>
  <script defer src="/__/firebase/6.4.1/firebase-auth.js"></script>
  <script defer src="/__/firebase/6.4.1/firebase-firestore.js"></script>
  <script defer src="/__/firebase/6.4.1/firebase-messaging.js"></script>
  <script defer src="/__/firebase/6.4.1/firebase-storage.js"></script> -->
  <script defer src="/__/firebase/init.js"></script>

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular-route.min.js"></script>

  <!-- AngularFire -->
  <script src="https://cdn.firebase.com/libs/angularfire/2.3.0/angularfire.min.js"></script>

请问为什么还会出现这个错误(snapshotChanges is not a function)?我需要它to include the doc.id in my mapping result,谢谢!

如果您使用普通 JavaScript SDK 来查询 Firestore,并且您想要将侦听器附加到查询,您应该为此使用 onSnapshot()

如果您想改用 AngularFire API 并使用 snapshotChanges,那将需要通过它自己的 API(参见 link),这与普通的 JavaScript SDK 不同。