力asyncvalidators在angularjs [英] force asyncvalidators in angularjs

查看:222
本文介绍了力asyncvalidators在angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题 - 有一个网页,是对所有人开放。如果非注册用户进来,节省了提交表单有一个登录模式,询问登录。

My problem - there is a web page which is accessible to all. If unregistered user comes in and saves the form on submit there is a login modal which asks for login.

如果是新用户,他就会registrate和preSS再次提交。
如果用户是不是新的,他将登录名和preSS再次提交。

If user is new he will registrate and press submit once again. If user is not new he will login and press submit once again.

如果注册的用户访问页面的表单名称正在验证与异步验证:

If registered user visits the page form name is being validated with async validator:

app.compileProvider.directive('nameAvailable', ['$q', '$http', 'service', function ($q, $http, service) {
        return {
            restrict: 'AE',
            require: 'ngModel',
            link: function ($scope, elem, attrs, ngModel) {
                ngModel.$asyncValidators.queryName = function (queryName) {
                    --logic
                }
            }
        }
    }]);

如果注册的用户有这种形式保存在相同的名称,然后,如果他来填充它会失败,然后登录。

And if registered user has this form saved with the same name then it will fail if he fills it and then log in.

问题是 - 我怎么可以强制验证该字段用户登录后在

Question is - how can I force validation on that field after user logs in?

有一件事,我发现是使用ngModelController和呼叫的validate(),但如果要访问它在我的控制器?

One thing which I found is to use ngModelController and call validate(), but where to access it in my controller?

感谢您!

推荐答案

我创建了 plunker 样本如何来验证角方式异步数据。

I have created the plunker with sample how to validate async data in angular way.

下面更新 plunker 与验证按钮。

这篇关于力asyncvalidators在angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆