我试图让表单验证与一个角度向导工作 [英] I'm trying to get form validations to work with an Angular Wizard

查看:107
本文介绍了我试图让表单验证与一个角度向导工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的应用程序的注册过程的角度向导。

I am using an angular wizard for my app's registration process.

角向导 -
https://github.com/mgonto/angular-wizard

但是,不管我怎么努力,在向导的每一步都是不允许的表单验证(这基本上出来与棱角分明的箱子,并与的FormController使用表格和$错误的对象。

However, no matter what I try, each step of the wizard is not allowing for form validation (which basically comes out of the box with angular and the use of forms with the FormController and the $error object.

我已经发布对项目的问题,关于表单验证的页面,但我还没有从该项目的所有者或任何其他用户的工作code的例子听到了,所以我在这里希望一些更高级的用户可以提供帮助。

I have posted on the project's issues page regarding form validation, but I have not heard from the owner of the project or from any other users with examples of working code, so I'm hoping some more advanced users here can help.

呵呵,帮助隔离问题,我只包括在我jsfiddles第一步的HTML。

Oh and to help isolate the problem, I have only included the html for the first step in my jsfiddles.

验证问题 - https://github.com/mgonto/angular-wizard/issues / 41

验证问题的网页链接到我的jsfiddles和其他努力。

The validation issue page links to my jsfiddles and other efforts.

这是一个范围问题????如果是这样,我怎么解决呢?目前,当我点击下一步按钮,它只是通过向导的进展,当我尝试到$错误对象发送到控制台,我得到的是不确定。

Is this a scoping problem???? If so, how do I get around it? Currently when I click the Next button, it just progresses through the wizard, and when I try to send the $error object to the console, all I get is "undefined".

角文档(表单属性,并参考$错误) - https://开头docs.angularjs.org/api/ng/type/form.FormController

Angular docs (form properties and reference to $error) - https://docs.angularjs.org/api/ng/type/form.FormController

推荐答案

这绝对是一个范围界定问题。我是能够通过进入(在控制器)的子元素的范围和定义中的变量视图(HTML)作为是$父元素的一部分,以得到的东西到工作。这意味着所有的变量以HTML被设置为

It's definitely a scoping problem. I was able to get things to work by reaching into the scope of a child element (in the controller) and by defining the variables in the view (html) as being part of the $parent element. This means that all of the variables are set in HTML as

ng-model="$parent.variableName";

从控制器更改此变量的值需要一个电话如下:

Changing this variable's value from the controller requires a call as follows:

$scope.$$childTail.variableName = 'something that you want to change the value to';

但是深入到$$ childTail是一个没有没有。这整个项目需要返工如果你问我来解决这个问题的范围界定。而且需要有关于如何访问验证变量的文档,如果修订后的项目使用任何典型的角数据绑定之外。

But reaching into $$childTail is a no-no. This whole project needs to be reworked to fix the scoping problem if you ask me. And there needs to be documentation on how to access validation variables if the revised project uses anything outside of typical angular data binding.

我的解决方案code附于学家,下文。

My solution code is attached in gists, below.

控制器设置
https://gist.github.com/Shawful/a4f8ff5097eabc5306f4

HTML设置
https://gist.github.com/Shawful/f8dc97d6fd88bbb111f9

这篇关于我试图让表单验证与一个角度向导工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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