需求背景:

在form中使用编写的某component directive时。想通过form's name来对form中控件进行操作,
如使用$invalid等来ng-disabled btn。

解决方式:

通过使用form.$addControl将控件中的control注冊到form中,既可使用form's name.xxx.$invalid方式来操作。

详细方法:

    tw.directive('nameForForm', function() {
return {
restrict: 'A',
require: "?ngModel",
link: function($scope, elem, attrs, ngModelCtrl) { var formController = elem.controller('form') || {
$addControl: angular.noop
}; ngModelCtrl.$name = attrs.workflowNameForForm;
formController.$addControl(ngModelCtrl); $scope.$on('$destroy', function() {
formController.$removeControl(ngModelCtrl);
}); return true;
}
};
});

使用方式:

component:

<div class="btn-group select select-block mbn">
...
<input type="text" ng-show="false" ng-model="selectedValue" ng-required="selectRequired"
name-for-form="{{nameForForm}}" />
</div>

注意:在component中引入nameForForm,且scope中加入nameForForm: '@'


页面使用component:

<tw-select-list name-for-form="city" ... />

參考:http://www.ngnice.com/posts/81c1eb92bfbde0

AngularJS form $addControl 注冊控件control的更多相关文章

  1. Leaflet:控件Control相关

    Leaflet官方文档中只给出了4种控件:Zoom.Attribution.Layers.Scale:它们都是继承自Control类,具体可以参考Control. Control Zoom.Scale ...

  2. 线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~ 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析

    看两个例子,一个是在一个进程里设置另外一个进程中控件的属性.另外一个是在一个进程里获取另外一个进程中控件的属性. 第一个例子 最近,在做一个使用线程控制下载文件的小程序(使用进度条控件显示下载进度)时 ...

  3. [转]通过AngularJS directive对bootstrap日期控件的的简单包装

    本文转自:http://www.cnblogs.com/Benoly/p/4109460.html 最近项目上了AngularJS,而原来使用的日期控件的使用方式也需要改变,于是开始了倒腾,看了官方的 ...

  4. [整理]通过AngularJS directive对bootstrap日期控件的的简单包装

    最近项目上了AngularJS,而原来使用的日期控件的使用方式也需要改变,于是开始了倒腾,看了官方的例子,可以使用AngularJS的directive做简单的处理,这样在html里直接使用申明的的形 ...

  5. 【经验】Angularjs 中使用 layDate 日期控件

    layDate 控件地址:http://laydate.layui.com/ 前情:原来系统中使用的日期控件是UI bootstrap(地址:https://angular-ui.github.io/ ...

  6. C# WinForm窗体 控件Control 的 Invalidate、Update、Refresh的区别

    Control.Refresh - does an Control.Invalidate followed by Control.Update.Refresh: 强制控件使其工作区无效并立即重绘自己和 ...

  7. AngularJs的UI组件ui-Bootstrap---tabs控件

    tabs控件使用uib-tabset指令和uib-tab指令,效果是这样的: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo ...

  8. .net控件Control透明

    public partial class tspControl : UserControl { public tspControl() { InitializeComponent(); SetStyl ...

  9. AngularJS页面【uib-dropdown】控件在模态窗口(弹出窗)中无法使用问题

    如果你的下拉框中有属性 dropdown-append-to-body 将它去掉,即可正常使用该插件. <div class="btn-group dropdown" uib ...

随机推荐

  1. Kyle 的 iOS 面试题

    1.简单介绍下你对swizzling方法的了解,一般你什么时候使用. 2.有三个对象 A,B,C..:A retain B, B retain C, C retain B..当 A release B ...

  2. select 下拉框的选中项的change事件

    HTML文件 <span style="float: left;">类      型:   <select id="type" class=& ...

  3. virtualenv 环境安装

      # Python 2.7.6:wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xztar xf Python-2.7.6.tar. ...

  4. centos7 mongodb3.2与3.4版本安装(转)

    一.安装环境及配置yum vi /etc/yum.repos.d/mongodb-org-3.2.repo [mongodb-org-3.2] name=MongoDB Repository base ...

  5. ISP模块之RAW DATA去噪(一)

    ISP(Image Signal Processor),图像信号处理器,主要用来对前端图像传感器输出信号处理的单元,主要用于手机,监控摄像头等设备上. RAW DATA,可以理解为:RAW图像就是CM ...

  6. Vue表单和组件

    一.表单 v-model 指令在表单控件元素上创建双向数据绑定,v-model 会根据控件类型自动选取正确的方法来更新元素. <input v-model="message" ...

  7. RedHat虚拟机相关操作

    在VM虚拟机中安装完Redhat系统之后 如果需要用secureCRT连接linux系统的话 操作步骤如下: 1.进入linux系统,在终端输入ifconfig(注意,不是windows的ipconf ...

  8. tomcat修改默认访问首页

    找到conf下server.xml文件修改如下位置内容 <Host name="localhost" appBase="webapps" unpackWA ...

  9. Python3链接MySQL数据库

    Python 2.x 上连接MySQL的库倒是不少的,其中比较著名就是MySQLdb(Django项目都使用它:我也在开发测试系统时也使用过),见:http://sourceforge.net/pro ...

  10. 工业控制系统USB存储设备可信管理方案的(ICICS2015)论文PPT:TMSUI: A Trust Management Scheme

    本PPT是发表在ICICS2015 大会的论文 TMSUI: A Trust Management Scheme of USB Storage Devices for Industrial Contr ...