【问题标题】:Ionic with Firebase V.3 authentification带有 Firebase V3 身份验证的 Ionic
【发布时间】:2016-10-05 05:46:41
【问题描述】:

我目前为我的应用项目传递了 firebase v3,但我的身份验证系统不起作用,我不明白为什么。这是我的代码:

.controller('loginCtrl', function($scope) {
        $scope.loginEmail = function(){
            firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
              var errorCode = error.code;
              var errorMessage = error.message;
            });
        };
    })
    .controller('signinCtrl', function($scope) {
        $scope.signupEmail = function(){  
            firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
              var errorCode = error.code;
              var errorMessage = error.message;
            });
        };
    });

还有我的表格:

<form>
        <ion-list>
            <label class="item item-input">
                <span class="input-label">Username</span>
                <input type="text" placeholder="enter username..." ng-model="data.username">
            </label>
            <label class="item item-input">
                <span class="input-label">Email</span>
                <input type="email" placeholder="you@domain.com" ng-model="data.email">
            </label>
            <label class="item item-input">
                <span class="input-label">Password</span>
                <input type="password" placeholder="At least 6 characters" ng-model="data.password">
            </label>
        </ion-list>
        <button class="button button-stable button-block" ng-click="signupEmail()">Done</button>
    </form>

Chrome 控制台返回此消息:

ReferenceError: email is not defined

有人可以帮助我吗?

【问题讨论】:

    标签: javascript ionic-framework firebase firebase-realtime-database


    【解决方案1】:

    我认为您应该初始化一个变量 email 并将登录表单中的值存储在其中,然后再将其传递到 firebase 数据库。还要给它一个 id 以便可以选择元素。对密码也这样做。

    var email = document.getElementById('email').value;
    var password = document.getElementById('password').value;
    <form>
            <ion-list>
                <label class="item item-input">
                    <span class="input-label">Username</span>
                    <input type="text" placeholder="enter username..." ng-model="data.username">
                </label>
                <label class="item item-input">
                    <span class="input-label">Email</span>
                    <input id="email" type="email" placeholder="you@domain.com" ng-model="data.email">
                </label>
                <label class="item item-input">
                    <span class="input-label">Password</span>
                    <input id="password" type="password" placeholder="At least 6 characters" ng-model="data.password">
                </label>
            </ion-list>
            <button class="button button-stable button-block" ng-click="signupEmail()">Done</button>
        </form>
    现在调用 firebase 来创建用户。

    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
                  var errorCode = error.code;
                  var errorMessage = error.message;
                });

    【讨论】:

    • 成功了!仍然有一些错误,但我正在努力!非常感谢您的帮助!
    • 这种初始化变量的方法是完全错误的,你不应该推荐这种方法
    猜你喜欢
    • 2018-01-23
    • 2016-10-30
    • 2019-01-08
    • 1970-01-01
    • 2019-02-26
    • 2019-02-21
    • 2020-04-25
    • 1970-01-01
    • 2021-10-16
    相关资源
    最近更新 更多