【问题标题】:@firebase/database: FIREBASE WARNING: Exception was thrown by user callback. TypeError: Cannot read property 'myID' of undefined@firebase/database:FIREBASE 警告:用户回调抛出异常。 TypeError:无法读取未定义的属性“myID”
【发布时间】:2018-10-13 00:16:21
【问题描述】:

我刚刚构建了一个使用 geofire 定位的 angularjs 应用程序。它在生产中完美运行,但是当我将它部署到 firebase 时出现问题。我相信错误应该来自这里

getLocations(radius: number, coords: Array<number>) {
    console.log(radius, coords)
    this.geoFire.query({
        center: coords,
        radius: radius
    })
    .on('key_entered', (userKey, location, distance) => {
        //we need to check this because this.hits the behavioursubject already cached previous result and geofire fetches again each time we go back to homepage
        const existAlready = this.hits.value.filter(h=>h.userKey === userKey)
        if(existAlready.length > 0){
            return
        }
        console.log(userKey)
        const u = this.userList.query.ref
                      .child(`/${userKey}`)
                      .on('value',s=>{
                        const {name, address} = s.val()
                        console.log(s.val())
                        let hit = {
                            location,
                            distance,
                            name,
                            address,
                            userKey
                        }

                        let currentHits = this.hits.value
                        currentHits.push(hit)
                        this.hits.next(currentHits)

                        this.eventService.sendMessage(Constants.EVENT_MESSAGES.LOADING, true)
                      })
    })
}

上述代码旨在在应用加载后立即获取我周围的位置。但是我得到了这个错误

@firebase/database:FIREBASE 警告:用户抛出异常 打回来。 TypeError:无法读取未定义的属性“myID”

错误只出现在生产中

【问题讨论】:

    标签: angularjs firebase geofire


    【解决方案1】:

    不确定这是否是解决方案,但对我有用。我认为真正的问题发生在您部署新版本并且不清除缓存时。

    所以对我来说,每次部署时,我都必须再次清除缓存。

    有趣的是,这只是发生在 chrome 中。我在 Edge 中对其进行了测试,我不必经历那个。

    【讨论】:

      【解决方案2】:

      我的应用程序在生产中也遇到了同样的错误。唯一似乎解决它的方法是清除我的谷歌缓存、历史记录和 cookie。这不是一个永久性的修复方法,但请尝试看看它是否有帮助。

      【讨论】:

        【解决方案3】:

        我已用以下版本的库更正了错误

        npm uninstall firebase 
        npm uninstall angularfire2
        npm install firebase@^4.11.0
        npm install angularfire2@^5.0.0-rc.6
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-10-19
          • 1970-01-01
          • 2014-12-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多