angular-formly allows you to keep your forms as DRY as possible. TheoptionsTypes property is one way of composing your field configurations to keep your forms light-weight and DRY.

/* global angular */
(function() { 'use strict'; var app = angular.module('formlyExample', ['formly', 'formlyBootstrap']); app.run(function(formlyConfig) {
formlyConfig.setType({
name: 'ipAddress',
defaultOptions: {
templateOptions: {
label: 'IP Address',
placeholder: '127.0.0.1'
},
validators: {
ipAddress: function($viewValue, $modelValue) {
var value = $modelValue || $viewValue;
return !value || validateIpAddress(value);
}
}
},
controller: function($scope) {
console.log($scope);
}
}); function validateIpAddress(value) {
return value && /(\d{1,3}\.){3}\d{1,3}/.test(value);
} }); app.controller('MainCtrl', function MainCtrl() {
var vm = this;
// funcation assignment
vm.onSubmit = onSubmit; // variable assignment
vm.model = {};
vm.fields = [
{
type: 'input',
key: 'ipAddress',
optionsTypes: ['ipAddress'],
templateOptions: {
label: 'My IP Address'
}
}
]; // copy fields because formly adds data to them
// that is not necessary to show for the purposes
// of this lesson
vm.originalFields = angular.copy(vm.fields); // function definition
function onSubmit() {
alert(JSON.stringify(vm.model), null, 2);
}
}); })();

[AngularJS] angular-formly: Default Options的更多相关文章

  1. [AngularJS] Angular 1.3 $submitted for Form in Angular

    AngularJS 1.3 add $submitted for form, so you can use  $submitted  to track whether the submit event ...

  2. [AngularJS] Angular 1.3 Anuglar hint

    Read More: http://www.linkplugapp.com/a/953215 https://docs.google.com/document/d/1XXMvReO8-Awi1EZXA ...

  3. [AngularJS] Angular 1.3 ng-model-options - getterSetter

    getterSetter:  boolean value which determines whether or not to treat functions bound to ngModel as ...

  4. [AngularJS] Angular 1.3: ng-model-options updateOn, debounce

    <!DOCTYPE html> <html ng-app="app"> <head lang="en" > <meta ...

  5. [Angularjs]angular ng-repeat与js特效加载先后导致的问题

    写在前面 最近在项目中遇到这样的一个前端的bug,在ng-repeat中绑定的图片,有一个晃动的特效,在手机端浏览的时候,图片有时候会正常展示,有时就展示不出来.当时猜测是因为angularjs与特效 ...

  6. [AngularJS] Angular 1.5 $transclude with named slot

    In Angular 1.5, there is no link and compile. So use if you transclude, you cannot access the fifth ...

  7. [AngularJS] Angular 1.5 multiple transclude

    If you know ui-router, multi-transclude should be easy for you also. In previou Angular version < ...

  8. [AngularJS] Angular 1.3 ngMessages with ngAnimate

    Note: Can use $dirty to check whether user has intracted with the form: https://docs.angularjs.org/a ...

  9. AngularJs angular.identity和angular.noop详解

    angular.identity 函数返回本身的第一个参数.这个函数一般用于函数风格. ----------以上是官网对该接口的说明,只能说这个文档写得也太二,让人完全看不懂.要理解它的用途,可直接看 ...

随机推荐

  1. Memcached总结一:memcached简介及适用和不适应场景

    Memcached是免费的,开源的,高性能的,分布式内存对象的缓存系统(键/值字典),旨在通过减轻数据库负载加快动态Web应用程序的使用. Memcached是由布拉德·菲茨帕特里克(Brad Fit ...

  2. 乱想-What&Why

    今天去海淀书城看书,目的很明确,本来是想买<WCF技术剖析>的下册(2010年3月份买了上册,当时下册没出来),谁知这本书不单卖,要和上册一起卖,扫兴. 兴致减半,索性找了旁边的基本Jav ...

  3. 转载:简化IT程序员工作生活的4个窍门

    如果可以简化你的生活——少做枯燥的任务,将时间真正地用于完成事情,你愿不愿意去尝试?下面就让我一起来学一下如何让程序员工作生活变得简单的小窍门.如果你敢于倾听自己的心声,你会发现自己一天中的大多数时间 ...

  4. tarjan 算法讲解(转)

     转自:https://www.byvoid.com/blog/scc-tarjan/ 網誌 列表 標籤 項目 關於 聯繫 四月142009 作者:byvoid 閱讀: 158882 計算機科學 圖論 ...

  5. Linux kernel ‘xfs_attrlist_by_handle()’函数缓冲区溢出漏洞

    漏洞名称: Linux kernel ‘xfs_attrlist_by_handle()’函数缓冲区溢出漏洞 CNNVD编号: CNNVD-201311-392 发布时间: 2013-11-29 更新 ...

  6. 【转】自定义垂直的UISlider

    原文网址:http://www.cocoachina.com/bbs/read.php?tid=96282 怎样自定义垂直的UISlider? UISlider弄成垂直的代码就是:slider.tra ...

  7. hunnu---11547 你的组合数学学得如何?

    解析:比较简单的DP,从左向右一个一个连续着放,dp[X][Y]表示到第X个硬币的时候Y状态的方案数,Y=0表示x左边那个不是正面的,Y=1表示x左边那个是正面 如果左边不是正面,那么当前放正面的就把 ...

  8. [Jacky] Stoe load reload 区别

    load( Object options ) : Boolean 采用配置好的Reader格式去加载Record缓存,具体请求的任务由配置好的Proxy对象完成. reload( Object opt ...

  9. apache学习

    核心功能和多路处理模块: Core:apache HTTP服务器核心提供的功能,始终有效 Mpm_common:收集了被多个多路处理模块(MPM)实现的公共指令 其他普通模块: mod_actions ...

  10. mac osx App store 安装软件 发生错误

    app store 安装软件时发生错误 解决办法: 1. 进入如下目录: sh-3.2# cd Library/Application\ Support/App\ Store/ sh-3.2# pwd ...