2016-06-11 166 views
0

我无法检索我的控制器中的电子邮件的值。我的价值'未定义'。
我的形式:

<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> 

我的控制器:

app.controller('RegistrationController', function ($scope) { 
    $scope.user = {}; 
    $scope.submit = function() {  
     alert($scope.user.email); 
     alert(this.user.email); 
    }; 
}); 
+0

运行之前不是您的代码缩小了吗? –

+0

您可以创建[Plunker](https://plnkr.co/)吗? – Win

+0

将ng-click =“submit()”移动到

标记并将其更改为ng-submit =“submit()”,并且警报(this.user.email)行应该被删除,这是没有意义的在这方面。 – bryan60

回答

2

我认为,它的发生是因为角度验证您的输入,除非你提供有效的电子邮件 - 模式将undefined

See my plunker

input[email] directive documentation

+0

我同意。不确定他/她使用的输入是未定义的,但如果它看起来不像电子邮件地址,则它将被定义为未定义。 –