$observe 是Attribute对象的一个方法,用来监听DOM中属性值的变化。比如 attr1="{{name}}"

Attribute定义在directive中的link函数的第三个参数上。所以$observe只能用在directive中。

可以看到它的回调函数只有一个参数,就是新值。

    .directive('myCustomer', function(){
return {
link: function(scope, element, attrs) {
attrs.$observe('attr1', function(newVal) {
//....
})
}
}
})

总结如下:

$observe只能用在directive,$watch没有那么多限制,$watch是scope对象上的方法,所以可以用在控制器或者是directive的link方法中。

$observe只能用监听DOM属性值的变化,$watch可以监听表达式,表达式可以是一个函数或字符串。如果是字符串会使用$parse转换为函数。字符串表达式不能包含{{}}。

$observe的回调函数有newValue, $watch有oldValue和newValue

随机推荐

  1. Oracle诊断工具 - ORA-2730x Troubleshooting Tool

    通常情况下,ORA-27300 ORA-27301 ORA-27302错误的原因是操作系统的系统调用错误或者操作系统配置问题,错误格式:ORA-27300: OS system dependent o ...

  2. Oracle GoldenGate OGG管理员手册(较早资料)

    第一章 系统实现简述 前言 编写本手册的目的是为系统管理员以及相关操作人员提供 Oracle  Goldengat  软 件的日常维护和使用的技术参考: 3 ORACLE 第二章 OGG 日常维护操作 ...

  3. UIButton的两种block传值方式

    UIButton的两种block传值方式 方式1 - 作为属性来传值 BlockView.h 与 BlockView.m // // BlockView.h // Block // // Create ...

  4. iOS7中修改StatusBar的显示颜色

    iOS7中修改StatusBar的显示颜色 效果图如下: 在iOS7中想手动修改statusBar的颜色,第一步需要做的就是在plist文件中设置View controller-based statu ...

  5. file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known

    请求页面时候报错 file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not know ...

  6. gitlab+jenkins环境搭建.md

    gitlab+jenkins自动化部署环境搭建 环境说明 系统 主机 IP 安装软件 CentOS 7 study-1 192.168.100.51 gitlab.git CentOS 7 study ...

  7. objc_msgSend函数的实现

    毕竟汇编语言代码比较晦涩难懂,因此这里将函数的实现反汇编成C语言的伪代码: //下面的结构体中只列出objc_msgSend函数内部访问用到的那些数据结构和成员. /* 其实SEL类型就是一个字符串指 ...

  8. Hadoop学习之路(十六)Hadoop命令hadoop fs -ls详解

    http://blog.csdn.net/strongyoung88/article/details/68952248

  9. ganache-cli

    安装: npm install -g ganache-cli@6.1.8 使用: userdeMacBook-Pro:~ user$ ganache-cli -m "success rifl ...

  10. 解决nodejs运行程序卡死之后,程序后台运行的问题

    查看node进程 ps aux | grep node 查出的结果如下 root 1660 0.0 1.5 885024 15892 tty1 Sl+ Mar11 0:00 node server.j ...