【问题标题】:Firebase AuthStateListener failed to trigger functionFirebase AuthStateListener 未能触发功能
【发布时间】:2019-03-24 15:37:07
【问题描述】:

嗨,在我的 nativescript angular 应用程序中,我在应用程序启动时检查用户是否登录并相应地调用函数。代码如下:

ngOnInit() {
    firebase.init({
        onAuthStateChanged: function (data) {
            if (data.loggedIn) {
                this.navigateToHome();
            }
        },
    })

错误:

Firebase AuthStateListener failed to trigger function (data) { if (data.loggedIn) { this.navigateToHome(); ...<omitted>... } TypeError: Cannot read property 'navigateToHome' of undefined

【问题讨论】:

    标签: angular typescript firebase firebase-authentication


    【解决方案1】:

    转换为箭头函数解决了这个问题。

    ngOnInit() {
        firebase.init({
            onAuthStateChanged: (data) => {
                if (data.loggedIn) {
                    this.navigateToHome();
                }
            },
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-27
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      相关资源
      最近更新 更多