我试图建立一个角的形式,但我是新与它,所以我需要一些帮助:)角:检查值NG-模糊
我有一个字段“电子邮件”这应该是在用户离开该字段时进行检查。我的控制器中的一个函数应该检查输入值是否已经存在于数据库中(ajax/http)。
我发现'ng-blur'函数,并在我的控制器中创建了一个函数来检查电子邮件。但是,$ scope.user.email是未定义的,我不知道我做错了什么。有人能帮助我吗?
这是到目前为止我的代码:
HTML(玉)
p.claim-text Email
abbr.required.claim-text(title='required') *
input#billing_email.input-text.form-control.claim-input(type='email', placeholder='Email', value='', name='email', ng-model='user.email', ng-blur='checkEmail()' required)
p(ng-show="registerForm.email.$invalid && !registerForm.email.$pristine").help-block Invalid emailadres
p(ng-show="emailExists").help-block User exists! Click here to login
控制器功能
$scope.checkEmail = function(){
console.log($scope.user.email);
$http({
method: 'GET',
url: '[someurl]',
data: $scope.user.email,
}).then(function successCallback(response){
//if response is true, set emailExists to true;
}, function errorCallback(response){
});
}
,而不是玉代码,就可以显示生成的HTML代码?何时你的'$ scope.user'对象被初始化? –
@NVO:试试我的代码,我添加了正在运行的剪辑 –