angular 之 $scope的 $apply $eval $digest
2016-01-21 00:00
501 查看
$apply:function(expr){ try{ beginPhase('$apply'); try{ return this.$eval(expr); } finally{ clearPhase(); } } catch(e){ $exceptionHander(e); } finally{ try{ $rootScope.$digest(); } catch(e){ $exceptionHander(e); throw e; } } }
对于 $apply 其实 内部还是调用了 $eval() $rootScope.$digest()
$eval:function(expr,locals){ // 调用了 $phase 服务 return $phase(expr)(this,locals); }
对于digest 方法
官方介绍 processes all of the watchers of the current scope and its children, because a watcher's listener can change the model,the digest keeps calling the watchers until no more listeners are firing. this means that it is possible to get into an infinite loop , the function will throw 'maximum iteration limit exceeded' if the number of iteration exceeds 10; usually you don't call digest() directly in controllers or in directive . instaad, you should call $apply ; 大概解释 就是 $digest 是一个watchers 的大集合,用于监听watcher 的内容变化,然后做脏值检查的。 不推荐直接使用$digest 方法,而是调用 $apply .
// 脏值检查 $digest:function(){ // 实现比较复杂 }
相关文章推荐
- Android 自定义 spinner (背景、字体颜色)
- 超全!整理常用的iOS第三方资源
- Unity 实时 半透明 阴影 shader
- Unity Motion Blur 运动模糊的实现
- Unity 中实现 打击感的物理
- list添加 append()和extend()的异同;tuple添加 add()和update()的异同
- Android Fragment
- Android图形显示系统——一张图片的显示流程
- iOS 9.2新增API
- 【译文】Thinking In Java (Introdution To Objects_The Progress of abstraction)01
- 微信公共号开发简单入门
- android逆向基础:apk 反编译 重打包 重签名
- R3下用ZwQueryObject/ZwDuplicateObject关闭互斥体和解除文件占用
- iOS 开发小记 (七)
- iOS开发 自定义navigationleftItem 之后手势失效的问题
- OCiOS开发:表格视图实现腾讯好友列表展开收缩效果
- Android_程序退出_关闭所有activity代码
- Gradle DSL method not found: 'android()
- iOS开发 masonry 设置tableHeadView
- unity初学(基本的方法)