无效电子邮件输入的模型值始终未定义。我希望能够检查用户是否输入了任何文本(即使它还不是有效的电子邮件地址)。
有关实施的更多详细信息,请查看 plnkr:http ://plnkr.co/edit/qV2eqGFhPvZSZKexDVF2?p=preview
html:
<body ng-controller="MainCtrl">
<form>
<div>
<label for="email">Email address</label>
<input ng-keyup="keyUp()" ng-change="changed()" type="email" name="email" id="email" ng-model='user.email'/>
</div>
</form>
</body>
控制器:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.user = {};
$scope.$watch('user.email', function (val){
console.log("Watch: "+$scope.user.email);
});
$scope.changed = function(){
console.log("Changed: "+$scope.user.email);
}
$scope.keyUp = function(){
console.log("KeyUp: "+$scope.user.email);
}
});
干杯。