$watch $apply and $evalAsync vs $timeout
$watch
$scope对象上的$watch方法会给Angular事件循环内的每个$digest调用装配一个脏值检查。
如果在表达式上检测到变化, Angular总是会返回$digest循环。
$watch函数本身接受两个必要参数和一个可选的参数:
watchExpression
watchExpression可以是一个作用域对象的属性,或者是一个函数。在$digest循环中的每
个$digest调用都会涉及它。
如果watchExpression是一个字符串, Angular会在$scope上下文中对它求值。如果它是一个
函数,那么Angular会认为它会返回应该被监控的值。
listener/callback
作为回调的监听器函数,它只会在watchExpression的当前值与先前值不相等(除了首次运
行初始化期间)时调用。
objectEquality(可选)
objectEquality是一个进行比较的布尔值,用来告诉Angular是否检查严格相等。
$watch函数会给监听器返回一个注销函数,我们可以调用这个注销函数来取消Angular对当
前值的监控。


$evalAsync vs $timeout
http://stackoverflow.com/questions/17301572/angularjs-evalasync-vs-timeout
To summarize:
if code is queued using $evalAsync from a directive, it should run after the DOM has been manipulated by Angular, but before the browser renders
if code is queued using $evalAsync from a controller, it should run before the DOM has been manipulated by Angular (and before the browser renders) -- rarely do you want this
if code is queued using $timeout, it should run after the DOM has been manipulated by Angular, and after the browser renders (which may cause flicker in some cases)
$apply
http://blog.csdn.net/dm_vincent/article/details/38705099
如果你在AngularJS上下文之外的任何地方修改了model,那么你就需要通过手动调用$apply()来通知AngularJS。这就像告诉AngularJS,你修改了一些models,希望AngularJS帮你触发watchers来做出正确的响应。
随机推荐
- 使用Git的Push出现rejected - non-fast-forward错误
通过查阅资料,发现是文件冲突问题,即本地和远程的Repository中的文件出现了冲突所致,重新检查了一下,发现是在建立Repository时,添加了ReadMe.txt文件,导致和本地得项目分支不一 ...
- Cucumber(一): Preparation
Every time I wrote some code in ruby and executed our cucumber features I craved for something simil ...
- 帝国CMS如何自动生成sitemap.xml网站地图文件
登录网站的后台http://你的域名/e/admin/ 进入后台栏目 =>增加自定义页面 =>选择直接页面,页面名称为:网站地图,文件名修改为 ../../sitemap.xml 内容填 ...
- MVC Html.BeginForm 与 Ajax.BeginForm 使用总结
最近采用一边工作一边学习的方式使用MVC5+EF6做一个Demo项目, 期间遇到不少问题, 一直处于研究状态, 没能来得及记录. 今天项目进度告一段落, 得以有空记录学习中遇到的一些问题. 由于MVC ...
- HTML5 学习笔记(一)——HTML5概要与新增标签
目录 一.HTML5概要 1.1.为什么需要HTML5 1.2.什么是HTML5 1.3.HTML5现状及浏览器支持 1.4.HTML5特性 1.5.HTML5优点与缺点 1.5.1.优点 1.5.2 ...
- Windows Commands and API
Shortcuts ... Symbolic Links https://en.wikipedia.org/wiki/NTFS_symbolic_link Hard Links https://en. ...
- [8.3] Magic Index
A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted ar ...
- 【尺取】POJ 3320
POJ 3320 Jessica's Reading Problem 题意:一本书P页,第i页有ai知识点,问你至少从某一处开始连续要翻多少页才能复习完所有的知识点,不能跨页翻. 思路:<挑战程 ...
- Logback_日志使用详解(转)
概述 Logback建立于三个主要类之上:日志记录器(Logger),输出端(Appender)和日志格式化器(Layout).这三种组件协同工作,使开发者可以按照消息类型和级别来记录消息,还可以在程 ...
- lua 字符串 正则表达式 转义 特殊字符
string.gsub 函数有三个参数:目标串,模式串,替换串.基本作用是用来查找匹配模式的串,并将使用替换串其替换掉: s = string.gsub("Lua is good" ...