我想用ng-keypress检查电子邮件复制。所以我宣布了模特“usrEmail”。当它用于“寄存器”方法时,它可以与输入值绑定,但在“校验双乘”中不能与输入值绑定。
如何解决这个问题??
signup.html
<input type="email" class="form-control" name="usrEmail" ng-model="usrEmail" ng-required="true" ng-keyup="checkDuplication()">
...
<button class="btn btn-primary full-width" ng-click="register()">Register</button>signup.js
var methods = {
checkDuplication: function($scope) {
$scope.usrEmail;
console.log($scope.usrEmail); // undifined!!!!!!!
...
},
register: function($scope){
$scope.user.usrEmail = $scope.usrEmail; // successfully binded!
...
}谢谢!
发布于 2018-03-30 05:01:31
您不应该将$scope作为参数传递给Singup.js (控制器/服务)。您应该在像ng-keyup="checkDuplication(usrEmail)"这样的标记中传递模型,并在函数中使用,如:
checkDuplication: function(usrEmail) {
console.log(usrEmail);
...
}下面是一个需要帮助的柱塞:https://plnkr.co/edit/bl4Ui3LbDckvrg8XDjxP?p=preview
发布于 2018-03-30 04:22:50
尝尝这个
<input type="email" class="form-control" name="usr-Email" ng-model="usrEmail" ng-required="true" ng-keyup="checkDuplication()">https://stackoverflow.com/questions/49566954
复制相似问题