簡體   English   中英

從 Firebase 獲取數據,日期范圍在 Angular 2

[英]Getting data from Firebase with date range in Angular 2

我有一個像這樣的 Firebase 集合:

我正在嘗試使用以下代碼獲取具有日期范圍條件的數據:

票-form.component.ts

onSubmmitDates(value: any) {
    debugger;
    this.ts.getSpecificTicket(value.dateFrom, value.dateTo).subscribe((data: any) =>{
      console.log(data);
    });
}

票務服務.ts

private ticketList: AngularFireList<any>;

constructor(
    private firestore: AngularFirestore,
    private afDatabase: AngularFireDatabase,
) { }
getSpecificTicket(dateFrom: Date, dateTo: Date): any {
    this.ticketList = this.afDatabase.list('tickets', ref =>
    ref.orderByChild('issuedOn').startAt(dateFrom.toString()).endAt(dateTo.toString()));
    return this.ticketList.snapshotChanges();
}

當我運行它時,我得到這個錯誤:

ERROR 錯誤:permission_denied at /tickets:客戶端無權訪問所需數據。 在 errorForServerCode (index.cjs.js:642) 在 onComplete (index.cjs.js:8944) 在 Object.onComplete (index.cjs.js:12467) 在 index.cjs.js:11611 在 PersistentConnection.push../ node_modules/@firebase/database/dist/index.cjs.js.PersistentConnection.onDataMessage_ (index.cjs.js:11853) 在 Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection .onDataMessage_ (index.cjs.js:11170) 在 Connection.push../node_modules/@firebase/database/dist/index.cjs.js.Connection.onPrimaryMessageReceived_ (index.cjs.js:11164) 在 WebSocketConnection.onMessage ( index.cjs.js:11065) 在 WebSocketConnection.push../node_modules/@firebase/database/dist/index.cjs.js.WebSocketConnection.appendFrame_ (index.cjs.js:10657) 在 WebSocketConnection.push../node_modules /@firebase/database/dist/index.cjs.js.WebSocketConnection.handleIncomingFrame (index.cjs.js:10707)

這是我的規則:

在此處輸入圖像描述

我能做些什么來解決這個問題?

確保您已授予讀/寫權限,如圖所示。

在此處輸入圖像描述

檢查您對數據庫 Firebase 的權限。 如果您處於開發模式,您可以刪除權限,但任何人都可以訪問。 暫時你在開發的時候,訪問權限沒有問題,你可以簡單的做如下圖。

service cloud.firestore {
  match /databases/{database}/documents {
  match /{document=**} {
   allow read, write;
  }
 }
}

在規則部分。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM