簡體   English   中英

需要偵聽表以了解Firebase中的更改

[英]Need to listen to a table for changes in Firebase

在我的Angular 2應用程序中,我需要偵聽表以了解Firebase中的更改。 我正在使用Angular2,Firebase和TypeScript。 我有一個偵聽器,但更改數據庫表時不會觸發。

我需要它在表被更新/更改時總是命中監聽器 看來我需要將聽眾放在一個全球范圍內。 當前,我的偵聽器在服務文件中。

這是我的嘗試:

this.adminNotifications = new Firebase(_environment.firebaseUrl + "/adminNotifications");

taskSchedulerListner = (): Promise<any> => { 
    this.adminNotifications.on('value', function(snapshot: any) {
        console.log("admin notification hit!");
    });
}

讓我知道您是否需要查看其他任何代碼。 目前,我只希望在adminNotifications表更改時點擊監聽器。 換句話說,我希望上面示例中的console.log方法被點擊。

我沒有任何控制台錯誤,更改表adminNotifications時什么也沒有發生。

我遇到了同樣的問題,並且意識到,在返回時,您不必在答應中包裝您的偵聽器。 只需將您的代碼調整為此。

this.adminNotifications = new Firebase(_environment.firebaseUrl + "/adminNotifications");

taskSchedulerListner = this.adminNotifications.on('value', function(snapshot: any) {
        console.log("admin notification hit!");
    });

暫無
暫無

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

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