1. 表达式
- {{js表达式}}
- 从作用域对象中读取对应的属性数据来显示数据
- 不支持if/for/while
- 支持三目表达式
2. 指令
- 指令 : 自定义标签属性/标签
- 常用的指令:
- ng-app: 指定模块名,angular管理的区域
- ng-model: 双向绑定,输入相关标签
- ng-init: 初始化数据
- ng-click: 调用作用域对象的方法(点击时)
可以传$event - ng-controller: 指定控制器构造函数名,内部会自动创建一个新的子作用域(外部的)
- ng-bind: 解决使用{{}}显示数据闪屏(在很短时间内显示{{}})
- ng-repeat: 遍历数组显示数据, 数组有几个元素就会产生几个新的作用域
- $index, $first, $last, $middle, $odd, $even
- ng-show: 布尔类型, 如果为true才显示
- ng-hide: 布尔类型, 如果为true就隐藏
- ng-class: 动态引用定义的样式 {aClass:true, bClass:false}
- ng-style: 动态引用通过js指定的样式对象 {color:‘red’, background:‘blue’}
- ng-mouseenter: 鼠标移入监听, 值为函数调用, 可以传$event
- ng-mouseleave: 鼠标移出监听, 值为函数调用, 可以传$event
3. 过滤器
- 作用: 在显示数据时可以对数据进行格式化或过滤
- 单个—>格式化(将别的类型的数据转换为特定格式的字符串)
- 多个—>格式化/过滤
- 不会真正改变被操作数据
- {{express | 过滤器名:补充说明}}
- 常用过滤器:
-
currency:货币格式化(文本)
-
number:数值格式化(文本)
-
date:将日期对象格式化(文本)
-
json: 将js对象格式化为json(文本)
-
lowercase : 将字符串格式化为全小写(文本)
-
uppercase : 将字符串格式化全大写(文本)
-
limitTo:从一个数组或字符串中过滤出一个新的数组或字符串
- limitTo : 3 limitTo : -3
-
orderBy : 根据指定作用域属性对数组进行排序
- {{[2,1,4,3] | orderBy}} 升序
- {{[2,1,4,3] | orderBy:‘-’}} 降序
- {{[{id:2,price:3}, {id:1, price:4}] | orderBy:‘id’} id升序
- {{[{id:2,price:3}, {id:1, price:4}] | orderBy:’-price’} price降序
-
filter : 从数组中过滤返回一个新数组
- {{[{id:22,price:35}, {id:23, price:45}] | filter:{id:‘3’}} //根据id过滤
- {{[{id:22,price:35}, {id:23, price:45}] | filter:{$:‘3’}} //根据所有字段过滤
-