在Polymer 3.0中访问元素

时间:2019-02-21 16:02:30

标签: polymer polymer-starter-kit polymer-3.x

无法调用函数。无法通过this。$。id访问元素。我可以在Polymer 2.0中完成所有这些操作,但是正在尝试升级到Polymer 3.0。

ready() {
    super.ready();

    this.$.login.addEventListener('login', this.login);
    this.$.login.addEventListener('forgot-password', this.forgotPassword);
}

login(e) {
    const username = e.detail.username;
    const password = e.detail.password;

    auth.signInWithEmailAndPassword(username, password)
        .then(user => {
            // why doesn't this work
            this.getUserFromFirestore(user.uid);
        })
        .catch(error => {
            console.log(error);
            // why doesn't this work
            this.$.login.error = true;
        });
}

getUserFromFirestore(uid) {
    firestore.collection('users').doc(uid)
        .get()
        .then(doc => {
            let user = doc.data();
            console.log(user.role);
        })
        .catch(error => {
            console.log(error);
        });
}

使用Firebase身份验证。那行得通,但是当我去调用我的getUserFromFirestore函数时,我收到一个“ TypeError:this.getUserFromFirestore不是一个函数”

1 个答案:

答案 0 :(得分:0)

我只是在猜测...

您尝试过

constructor () {
    this.login = this.login.bind(this);
}