Angular form
参考 http://blog.xebia.com/2013/10/15/angularjs-validating-radio-buttons/
http://stackoverflow.com/questions/19632933/angularjs-group-check-box-validation
html
验证的require maxlength 等是根据 表单名.元素名
controller获取数据是根据ng-model
<form name="form1" class="form-group"
ng-class="{ 'has-error' : form1.username.$invalid && !form1.username.$pristine }">
<label>Username</label>
<input type="text" name="username" class="form-control" ng-model="user.username" ng-minlength="3" ng-maxlength="8" required/>
<p ng-show="form1.username.$error.required" class="help-block">Tell us your Username</p>
<p ng-show="form1.username.$error.minlength" class="help-block">Username is too short.</p>
<p ng-show="form1.username.$error.maxlength" class="help-block">Username is too long.</p>
<br>
<label>Email</label>
<input class="form-control" type="email" ng-model="user.email" name="email" required/><br />
<p ng-show="form1.email.$error.required" class="help-block">Tell us your email.</p>
<p ng-show="form1.email.$error.email" class="help-block">email wrong.</p>
<label>Gender:</label>
<label class="radio" ng-repeat="gen in genders">
<input type="radio" ng-model="user.gender" name="gender" value="{{gen.id}}" required/><span>{{gen.text}}</span>
</label>
<label>Hobby:</label>
<label class="checkbox" ng-repeat="hobby in hobbies">
<input type="checkbox" ng-model="user.hobbies[hobby.id]" name="hobby" value="{{hobby.id}}" required/><span>{{hobby.text}}</span>
</label>
<p>自定义验证</p> <button ng-click="save(user)" class="btn btn-default">Submit</button>
<button ng-click="reset()" class="btn btn-default">reset</button>
</form>
<pre>form = {{user | json}}</pre>
<pre>saved = {{saved | json}}</pre>
controller
//测试form1
$scope.saved = {};
$scope.genders = [{id:'1',text:'male'},{id:'2',text:'female'}];
$scope.hobbies = [{id:'1',text:'haha'},{id:'2',text:'hehe'}];
$scope.save = function(user){
$scope.saved = angular.copy(user);
}
$scope.reset = function() {
console.log($scope.user);
$scope.user = angular.copy($scope.saved);
};
Angular form的更多相关文章
- 细说angular Form addControl方法
在本篇博文中,我们将接触angular的验证.angular的验证是由form 指令和ngModel协调完成的.今天博主在这里想要说的是在验证在的一种特殊情况,当验证控件没有没有name属性这是不会被 ...
- angular form 验证
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- angular form 验证 ngMessage
<!DOCTYPE HTML> <html ng-app="deliciousApp"> <head> <meta charset=&qu ...
- Angular - - form.FormController、ngModel.NgModelController
form.FormController FormController跟踪所有他所控制的和嵌套表单以及他们的状态,就像有效/无效或者脏值/原始. 每个表单指令创建一个FormController实例. ...
- [Angular Form] ngModel and ngModelChange
When using Radio button for Tamplate driven form, we want to change to the value change and preform ...
- angular form set dynamic control(form动态设置control)
实现效果 form表单控件的实时更新 效果如图 关键代码 validateForm: FormGroup; // 表单校验 constructor( private fb: FormBuilder ) ...
- angular(常识)
我觉得angularjs是前端框架,而jquery只是前端工具,这两个还是没有可比性的. 看知乎上关于jquery和angular的对比http://www.zhihu.com/question/27 ...
- 如何优雅的使用 Angular 表单验证
随便说说,这一节可以跳过 去年参加 ngChine 2018 杭州开发者大会的时候记得有人问我: Worktile 是什么时候开始使用 Angular 的,我说是今年(2018年) 3 月份开始在新模 ...
- [转]Angular: Hide Navbar Menu from Login page
本文转自:https://loiane.com/2017/08/angular-hide-navbar-login-page/ In this article we will learn two ap ...
随机推荐
- 又一个类dapper轮子:VIC.DataAccess
DataAccess Author: Victor.X.Qu Email: fs7744@hotmail.com DataAccess is a c# project for sql data map ...
- VBA基础概念
一:VBA对象 'VBA对象 'VBA中的对象其实就是我们操作的具有方法.属性的excel中支持的对象 'Excel中的几个常用对象表示方法 '1.工作簿 ' Workbooks 代表工作簿集合,所有 ...
- C++_内部类
C++ 内部类和外部类之间的相互调用
- MFC CListCtrl得到ctrl,shift多选的行号
vector<int> selVect; int count = m_consumeList.GetItemCount(); //你的列表多少行 for (int i = 0; i< ...
- 基于jQuery的Jsonp跨域[Get方式]
由于目前的项目需要无刷新的跨域操作数据,整理了下自己使用的基于jQuery的Jsonp跨域[Get方式]. 代码如下: Javascript部分 $(function(){ $.ajax({ asyn ...
- WinCE 5.0模拟器,在 win7 下安装后, VS2008里不显示
来源:http://blog.csdn.net/masterlonely/article/details/8302932 现状: Win7 32位旗舰版 VS2008 Team 在安装了: Windo ...
- zookeeper 学习笔记 (C语言版本)
1.zookeeper简介 zookeeper是Hadoop的子项目,在大型分布式系统中,zookeeper封装好了一些复杂易出错的服务,提供简单易用的接口,给使用者提供高效稳定的服务.这些服务包括配 ...
- SQL Server 全文索引
create table Document(ID int not null,Name nvarchar(255) not null,Body nvarchar(max) not null);go cr ...
- ElasticSearch Aggregation
http://zaiste.net/2014/06/concisely_about_aggregations_in_elasticsearch/
- Android updater-scripts(Edify Script)各函数详细说明(转)
这是Android系统来运行updater-scripts的Edify语言的基本介绍. 大部分的Edify命名都是函数,当调用这些函数结束的时候,会返回数据给脚本.当然,你也可以使用这些函数的返回值来 ...