angular attrs.$observe和$scope.$watch的区别
2024-10-20 11:35:06
http://stackoverflow.com/questions/14876112/difference-between-the-observe-and-watch-methods
https://docs.angularjs.org/api/ng/type/$compile.directive.Attributes
$observe()是Attributes 对象的一个方法,它只能用于observe/watch一个DOM attribute的value change.它只在directive内部被调用。当你需要监察、侦听一个包含interpolation的attribute的DOM时,你需要使用$observe()函数(比如:{{attrValue}},再比如select控件,当你选择一个option时,如果对应的属性作为触发过滤结果集这种场景时,可以$observe这个选择动作的结果(作为attr)
<div d1 attr1="{{prop1}}-test" attr2="prop2" attr3="33" attr4="'a_string'"
attr5="a_string" attr6="{{1+aNumber}}"></div>
$watch被用于监察、侦听一个model/scope属性,比如:scope.$watch(attrs.attr1)...
注意:angular normalize string
最新文章
- 如何参与一个 GitHub 开源项目?
- underscore.js依赖库函数分析一(遍历)
- 使用windows服务和MSMQ和进行日志管理(解决高并发问题)
- 深入认识JavaScript 中的this指针
- Linux查看日志命令
- DataTable Select 使用
- android的fragments管理
- Ecshop去掉模版中随机出现Ecshop版权的方法
- 51nod 1103 N的倍数 思路:抽屉原理+前缀和
- C语言编写一个简单游戏
- 源码解析flask的路由系统
- 某校高中生利用Python,巧妙获取考试成绩,看到成绩后无言以对!
- Hibernate Annotation 生成数据库表(UUId)
- Win10下搭建Git服务器
- Mysql phpStudy升级Mysql版本,流产了怎么办?
- RxSwift学习笔记4:disposeBag/scheduler/AnyObserver/Binder
- [BeiJing wc2012]连连看(建模,最小费用最大流)
- 利用opencv从USB摄像头获取图片
- DXP 内电层分割
- DevExpress v17.2新版亮点—WinForms篇(一)
热门文章
- du及df命令的使用
- 看一段Delphi导出到Word的源代码
- iphone数据存储之-- Core Data的使用
- Objective-C中.h、.m、.mm的区别
- C语言实现链表
- Python基础(4) - 变量
- Intellij IDEA自定义类模板和方法模板
- [转]How can I install the VS2017 version of msbuild on a build server without installing the IDE?
- (微信小程序)二 : 创建一个页面。
- mongodb操作之mongoose