0

I'm developing an app using the newest versions/SDK of

  1. Visual Studio
  2. Cordova
  3. Ionic
  4. AngularJS
  5. Firebase
  6. Genymotion

and I try to auth a user in my app via Firebase (email and password). I already searched the web for a solution but I simply don't get it working correctly.

Well, as soon as I click the register button (top right corner) I'll get this error message

Error message

This is the register.html (contains a form)

<ion-modal-view>
<div class="bar bar-header firstStart">
    <div class="button button-clear button-positive" ng-click="closeModal()">
       Schließen
    </div>
    <h1 class="title modalTitle">Registrieren </h1>
    <div class="button button-clear button-positive"
         ng-click="signupEmail()"> Speichern </div>
</div>

<ion-content class="has-header" padding="true">
    <div class="list list-inset">
        <label class="item item-input item-floating-label">
            <i class="icon ion-ios-email placeholder-icon"></i>
            <span class="input-label">E-Mail</span>
            <input type="email" ng-model="data.email" placeholder="E-Mail" id="email">
        </label>
        <label class="item item-input item-floating-label">
            <i class="icon ion-ios-locked placeholder-icon"></i>
            <span class="input-label">Passwort</span>
            <input type="password" ng-model="data.password"
                   placeholder="Passwort" id="password">
        </label>
    </div>
</ion-content>

app.js

    .controller('modalController', ['$scope', '$ionicModal','$firebase', 
     function ($scope, $ionicModal,$firebase)
     {
        $ionicModal.fromTemplateUrl('templates/register.html', {
        scope: $scope,
        animation: 'slide-in-up',
        backdropClickToClose: false,
        hardwareBackButtonClose: false,
        focusFirstInput: true
    }).then(function (modal) {
        $scope.modal = modal;
    });

    $scope.signupEmail = function () {
        $scope.data = {};
        var email = $scope.data.email;
        alert(email);
        var password = $scope.data.password;
        alert(password);
        /*if (email.length < 4) {
            alert('Please enter an email address.');
            return;
        }
        if (password.length < 4) {
            alert('Please enter a password.');
            return;
        }*/

        firebase.auth().createUserWithEmailAndPassword(email, password).catch(
        function (error)
        {
            // Handle Errors here.
            var errorCode = error.code;
            var errorMessage = error.message;
            // [START_EXCLUDE]
            if (errorCode == 'auth/weak-password') {
                alert('The password is too weak.');
            } else {
                alert(errorMessage);
            }
            if (errorCode == 'auth/argument-error') {
                alert('Error with arg');
            } else {
                alert(errorMessage);
            }
            console.log(error);
            // [END_EXCLUDE]
        });
        // [END createwithemail]
    };

    $scope.login = function () {
        firebase.auth().onAuthStateChanged(function (user) {
            if (user) {
                // User is signed in.
                alert("User already signed in");
            } else {
                // No user is signed in.
                firebase.auth().signInWithEmailAndPassword(email, password).catch(
              function (error)
              {
                 // Handle Errors here.
                 var errorCode = error.code;
                 var errorMessage = error.message;
                 alert("error during login:" + errorMessage + "Code: " + errorCode);
               })
            }
        });
    };

    $scope.openModal = function () {
        $scope.modal.show();
    };

    $scope.closeModal = function () {
        $scope.modal.hide();
    };
    // Cleanup the modal when we're done with it!
    $scope.$on('$destroy', function () {
        $scope.modal.remove();
    });
    // Execute action on hide modal
    $scope.$on('modal.hidden', function () {
        // Execute action
    });
    // Execute action on remove modal
    $scope.$on('modal.removed', function () {
        // Execute action
    });
}]);

Please note that app.js contains two controller because one modal opens another modal if the user taps on the button at the top right corner

This function causes the error

This function is placed in app.js, just wanted to highlight it for you.

$scope.signupEmail = function () {
    $scope.data = {};
    var email = $scope.data.email;
    alert(email);
    var password = $scope.data.password;
    alert(password);

    firebase.auth().createUserWithEmailAndPassword(email, password).catch(
        function (error) 
        {
           // Handle Errors here.
           var errorCode = error.code;
           var errorMessage = error.message;
           // [START_EXCLUDE]
           if (errorCode == 'auth/weak-password') {
             alert('The password is too weak.');
           } else {
            alert(errorMessage);
           }
           if (errorCode == 'auth/argument-error') {
            alert('Error with arg');
           } else {
            alert(errorMessage);
           }
           console.log(error);
           // [END_EXCLUDE]
       });
       // [END createwithemail]
     };

Note: As you may see I'm printing out the password and email the user typed in to see its value but the only result I get is Alert message

What am I doing wrong? Your answers are very appreciated.

Thanks!

Reporter
  • 3,897
  • 5
  • 33
  • 47
Big Dude
  • 264
  • 1
  • 6
  • 25

1 Answers1

0
$scope.data = {};

var email = $scope.data.email;
alert(email);

var password = $scope.data.password;
alert(password);    

Email is always undefined.

Big Dude
  • 264
  • 1
  • 6
  • 25
bojeil
  • 29,642
  • 4
  • 69
  • 76
  • I thought that since I bind the value of my input field in 'register.html' with '' to my variable 'var email = $scope.data.email' in my controller , I'll get the value of what the user is typing in...How can I accomplish that? If the user is filling in the form, I want to gather the information and use it. Thought I'd do that with data binding (ng-data) – Big Dude Sep 23 '16 at 08:06
  • Like he suggested [link](http://stackoverflow.com/questions/21040454/get-value-from-input-angularjs) – Big Dude Sep 23 '16 at 08:27