秒味课堂Angular js笔记------指令
1.属性指令
- angularjs样式相关指令:
- ng-class
- ng-style
- ng-href
- ng-src
- ng-attr-(suffix)
- ng-bind
- ng-cloak 没解析完之前标签是隐藏的,解析完后标签是显示的,控制css的指令
- ng-bind-template 支持多表达式'{{text}},{{text}}'
- ng-bind-html 解析字符串中的标签,需要依赖angular-sanitize.min.js
- ng-non-bindable 不解析表达式,就原样输出{{text}}
- ng-show
- ng-hide
- ng-if 当表达式为true ,该标签显示。并不是通过css操作,而且dom的添加删除的操作。
- ng-switch
- on
- default
- when
<div ng-switch on="bBtn">
<p ng-switch-default>默认的效果</p>
<p ng-switch-when = "false">切换的效果</p>
</div>
- ng-open 针对details标签,有兼容性,只支持chrome和Safari
<details ng-open="true"> //true显示下面列表,false不显示
<summary>Copyright 2011.</summary>
<p>All pages and graphics on this web site are the property of W3School.</p>
</details>
- ng-init 建议在循环嵌套中利用此指令定义初始循环变量
<div ng-controller = "Ctr" ng-init = "aIndex = $index ">
{{aIndex}}
</div>
- ng-include 引入模板
- ng-model 扩展,可以对数据添加条件,比如光标离开时更新数据。
<script type="application/javascript">
var sStyle = angular.module("sStyle",[]);
sStyle.controller("styleController",["$scope",function($scope){
$scope.text = "hello";
}])
</script>
<body>
<div ng-controller = "styleController">
<input type="input" ng-model="text" ng-model-options="{updateOn : 'blur'}"/>
<div>{{text}}</div>
</div>
</body>
- ng-controller
- as 针对面向对象
2.标签指令,用于表单验证中
- <a> 在ng-app中会阻止默认行为
- <select> <script type="application/javascript"> var sStyle = angular.module("sStyle",[]);
<script type="application/javascript">
var sStyle = angular.module("sStyle",[]);
sStyle.controller("styleController",["$scope",function($scope){
$scope.colors=[
{ name : "red"},
{ name : "yellow"},
{ name : "blue"}
];
}])
</script>
<body>
<div ng-controller = "styleController">
<a href ="">{{myColor.name}}</a>
<select ng-options = "color.name for color in colors" ng-model = "myColor">
</select>
</div>
</body>
- <textarea>
- <input>
- <form>
- novalidate 阻止html5表单自带的样式,比如没有按照type="email"格式输入,鼠标点击其他位置,此时边框会默认变红色。
3.表单验证
- $valid 表单验证成功返回true,验证失败返回false
- $invalid 相反
- $pristine 表单验证的值未修改返回true,修改过返回false
- $dirty 相反
- $error 验证失败
支持表单验证
- type
- number
- url
- required
秒味课堂Angular js笔记------指令的更多相关文章
- 秒味课堂Angular js笔记------Angular js中的工具方法
Angular js中的工具方法 angular.isArray angular.isDate angular.isDefined angular.isUndefined angular.isFunc ...
- 秒味课堂Angular js笔记------过滤器
不同过滤器的小demo. currency number uppercase json limitTo date orderBy filter <script> var filterMy ...
- 秒味课堂Angular js笔记------$scope.$watch和$scope.$apply
$scope.$watch(watchFn , watchAction , deepWatch) 其中,watchFn是带有angular表达式或函数字符串: watchAction是一个函数或者表达 ...
- Angular.js之指令学习笔记
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"& ...
- Angular JS笔记
1.引导程序 使用ng-app开始引导一个程序:标记了AngularJS应用的作用域 <!doctype html> <html lang="en" ng-app ...
- Angular JS 中 指令详解
Angular JS的强大功能就在于其可以自定义很多指令,现在就指令做一下详细的剖析. 一个Angular js 指令(directive)需要指定一个唯一的名字(myDirective)和一个函数, ...
- Angular JS - 7 - Angular JS 常用指令2
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Angular JS - 6 - Angular JS 常用指令
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- angular js 自定义指令
我们有些时候需要把后台返回过来的带有html标签的字符串binding到界面中一个指定的div或者其他的控制器中. 使用普通ng-bind不会自动解析出html语句. js中这样定义: app.dir ...
随机推荐
- PHP程序异常处理实现方法
一个异常(Exception)则是在一个程序执行过程中出现一个例外或是一个事件,它中断了指令的运行,跳转到其他程序模块继续执行.所以异常处理经常被当作程序的控制流程使用.无论是错误还是异常,应用程序都 ...
- div(固定宽度和不固定宽度)居中显示的方法总结
今天我总结一下css实现div居中的方法,有的是固定宽度的,还有的是不固定宽度的. 1.使用自动外边距实现DIV CSS居中 CSS中首选的让元素水平居中的方法就是使用margin属性—将元素的mar ...
- Gnuradio 实验二
今天根据教程做了实验二 要到了两个新的模块 一个是 FFT SINK, 其作用是按频谱输出信号. 另外一个就是 GUI Notebook ,起作用就是可以将SCOPE SINK 和 FFT SINK ...
- 前端面试题第一波,要offer的看过来~
一.HTML常见题目 01.Doctype作用?严格模式与混杂模式如何区分?它们有何意义? 02.HTML5为什么只需要写<!DOCTYPE HTML>? 03.行内元素有哪些?块级元素有 ...
- 浅谈iOS视频播放的N种解决方案
简 注册登录 添加关注 作者 Maru2016.03.22 20:46* 写了4349字,被135人关注,获得了207个喜欢 字数1621 阅读2895 评论43 喜欢159 header ...
- ubuntu matplotlib 安装
sudo apt-get install python-numpy //必须 sudo apt-get install python-matplotlib //必须
- listview底部增加按钮
View bottomView=getActivity().getLayoutInflater().inflate(R.layout.btn_my_course, null); myCourses = ...
- Steps
uva846:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- ISO7816协议中几个时间
T=0协议 第一.初始等待时间: 复位应答时,卡片回复的连续两个数据的起始沿之间的时间间隔,这个时间间隔不超过9600etu, 在波 特率为9600是,该时间为1s 第二.GT: 两个连续字符之间的最 ...
- 【HDOJ】1063 Exponentiation
这道题目莫名其妙的wa,又莫名其妙的过了. import java.util.Scanner; import java.math.BigDecimal; public class Main { pub ...