0

I'm trying to figure out how to get my user's email passed to my controller but I'm getting undefined for $scope.user.email. $scope is defined but there's no user object in there. Is there something wrong with my code?

html

<label class="item item-input">
  <span class="input-label">Email</span>
  <input ng-model="user.email" type="text">
</label>
<button ng-click="signInClick()" class="button button-full button-positive">
    Sign In
</button>

controller

.controller('WelcomeCtrl', function($scope) {
    $scope.signInClick = function() {
        console.log($scope.user.email);
    }
})

EDITS

The controller is linked via the js/apps.js and runs when my button is clicked so I know it's linked to WelcomeCtrl.

4
  • 2
    Is the input field within the right part of the html that is controllled by WelcomeCtrl? Could you make a jsfiddle or plunker with an example? Commented Apr 1, 2015 at 16:01
  • 1
    From the code that you're showing us you're not defining the user object anywhere Commented Apr 1, 2015 at 16:22
  • @inorganik what do you mean "defining the user object"? Steve I added an edit for your question, sorry for the confusion. Commented Apr 1, 2015 at 16:46
  • 1
    Exactly what I said, you never declare $scope.user anywhere, see @LanceVo's answer Commented Apr 1, 2015 at 22:53

1 Answer 1

1

because $scope.user is undefined.

.controller('WelcomeCtrl', function($scope) {
    $scope.user = {};
    $scope.signInClick = function() {
        console.log($scope.user.email);
    }
})
Sign up to request clarification or add additional context in comments.

2 Comments

Now user is an object but email is showing up as undefined.
Wow. I'm not even going to tell you why the email input value was coming across as undefined. I've been working on this project for way too long. Thanks Lance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.