HTML
<input class="input--style" type="email" name="email" ng-model="attempt.email" ng-keyup="check(attempt.email)" value="">
angularjs
$scope.check = function(text){
console.log(text);
$http({
method: 'POST',
url: '/api/user/check/',
data: {'email': $scope.attempt.email},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
}).success(function(data, status, headers, config) {
console.log(data);
$scope.user.emailvalid = data.email;
});
}
此输入位于模态内部,当模态触发上方角度位于该模态控制器内部时,当我开始在输入字段中键入console.log(text);
输出时,它按预期但工作undefined
$scope.attempt = {}
这是在我上面的角色剧本之前,我只是好奇为什么这不起作用。
答案 0 :(得分:3)
您是否真的想在每次用户按键时拨打服务器?你不喜欢debounce
至少~200ms吗?
尝试这样做:
<input class="input--style" type="email" name="email"
ng-model="attempt.email" ng-model-options="{ debounce: 200 }"
ng-change="check(attempt.email)" >
我忘记回答您的原始问题:您使用的是input
type="email"
,因此,除非有效的电子邮件角度设置为undefined
。因此,angular实际上对你有帮助,因为除非模型包含有效的电子邮件地址,否则您可能不想对服务器进行调用,对吧?所以,只需更改“检查”即可。功能,以便它首先检查值是否为undefined
,以及它是否未对服务器进行调用并将$scope.user.emailvalid
设置为false
。