0

I can't retrieve value of email in my controller. I get value 'undefined'.
My form:

<form role="form" novalidate>
    <div class="form-group">
        <input type="email" ng-model="user.email" name="email" id="email" class="form-control input-sm" placeholder="Email Address" formnovalidate>
    </div>
    <input type="submit" ng-click="submit()" value="Register" class="btn btn-info btn-block">
</form>

My controller:

app.controller('RegistrationController', function ($scope) {
    $scope.user = {};
    $scope.submit = function () {       
        alert($scope.user.email);
        alert(this.user.email);
    };
});
3
  • Wasn't your code minified before run? Commented Jun 11, 2016 at 20:01
  • Could you create Plunker? Commented Jun 11, 2016 at 20:05
  • move ng-click="submit()" to the <form> tag and change it to ng-submit="submit()", and the alert(this.user.email) line should be deleted, it doesn't make sense in this context. Commented Jun 11, 2016 at 20:13

1 Answer 1

2

I assume, it's happening because angular validates your input, and unless you provide valid email - model will be undefined

See my plunker

input[email] directive documentation

Sign up to request clarification or add additional context in comments.

1 Comment

I agree. Not sure what input he/she's using that it's coming up undefined but if it doesn't look like an email address it will be undefined.

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.