AngularJS:是有可能的具体形式输入字段从控制器失效? [英] AngularJS: is it possible to invalidate a specific form input field from the controller?

查看:95
本文介绍了AngularJS:是有可能的具体形式输入字段从控制器失效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有地址的文本输入框,每当输入的地址和下一个搜索按钮,输入框被点击,我地理code中的地址,并取代从地理$ C $结果输入文本CR。我还设置一个范围的变量addressOk。

I have a text input field for address, whenever the address is entered and search button next to the input field is clicked, I geocode the address and replace the input text with the result from the geocoder. I also set a scope variable 'addressOk'.

有没有可能这个特定的表单输入字段根据 $ scope.addressOk 无效或做我必须写这个地址的地理编码输入是无效的表单时指令需要的?

is it possible to invalidate this specific form input field according to $scope.addressOk or do I have to write a directive for this address geocoding input that invalidates the form when needed ?

推荐答案

我找到了解决办法,添加一个名称属性添加到<形式> <输入方式> ,然后在其控制器可以做到 $ scope.formName.inputName $ setValidity(errorKey器,isValid)

I found the solution, add a name attribute to the <form> and <input>, and then in the controller its possible to do $scope.formName.inputName.$setValidity(errorKey, isValid).

然后,它可以显示与错误的东西像 NG-秀=formName.inputName。$ error.errorkey

Then, its possible to display errors with something like ng-show="formName.inputName.$error.errorkey"

<一href=\"http://docs.angularjs.org/api/ng.directive:form\">http://docs.angularjs.org/api/ng.directive:form如果指定了name属性,表单控制器发布到该名称下的电流范围。

according to http://docs.angularjs.org/api/ng.directive:form If name attribute is specified, the form controller is published onto the current scope under this name.

这篇关于AngularJS:是有可能的具体形式输入字段从控制器失效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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