2016-07-31 57 views
3

我是聚合物和Firebase的新手,我正在练习这两种技术。我正在尝试为应用程序身份验证实施firebase-auth,但我去了一个“Can not read property”signInWithPopup'未定义的“错误。聚合物Firebase:未捕获TypeError:无法读取undefined属性'signInWithPopup'

我有这样的代码:

<paper-toolbar> 
    <span class="title">Sample!</span> 
    <paper-icon-button 
    icon="[[statusIcon(signedIn)]]" 
    on-tap="processAuth"> 
    </paper-icon-button> 
</paper-toolbar> 
<firebase-auth 
    id="auth" 
    app-name="emotions" 
    provider="google" 
    signed-in="{{signedIn}}" 
    user="{{user}}"> 
</firebase-auth> 

和processAuth

processAuth: function() { 
    this.$.auth.signInWithPopup(); 
} 

脚本和以下组件已经导入:

<link rel="import" href="../../bower_components/polymerfire/polymerfire.html"> 
<link rel="import" href="../../bower_components/polymerfire/firebase-auth.html"> 

难道我错过了什么?

对不起,这很菜鸟问题。

+0

之前的错误是告诉你,这个'。$。auth'是不确定的。 Polymer模块中的'template'标签内是否有'paper-toolbar'和'firebase-auth'标签?您正在使用的方法是访问嵌套在Polymer元素中的元素的正确方法。 – anthony

+0

“firebase-auth.html”已经导入到“polymerfire.html”中。无需再次导入它。 – Mohammed

回答

3

确保您有相同app-name初始化firebase-app您使用firebase-auth

+0

虽然我们该怎么做? – RuNpiXelruN

-2

尝试使用document.getElementById('auth')而不是this.$.auth

在我看来,this.$.auth正在尝试在paper-icon-button内找到一个#auth,这不在那里。 从processAuth检查console.log(this)以验证this指向哪里。

+0

'document.getElementById('auth')'用于访问Polymer元素之外的项目。 – anthony

相关问题