[AngularJS] $scope.$warchCollection
For the $watch in last article, we watch 'user.password', actually it is a string.
If you watch 'user', this object and we do something like:
function WatchCtrl ($scope) {
$scope.$watch('user', function (newVal, oldVal) {
console.log(newVal, oldVal);
});
}
Actually it won't work.
Because, $watch without the third param is a reference watching. If we add the third param:
function WatchCtrl ($scope) {
$scope.$watch('user', function (newVal, oldVal) {
console.log(newVal, oldVal);
}, true);
}
Then it lost value watching, but it is qiute expensive.
Actually we have another way to do that if what we are watching is an object by using $watchCollection:
function WatchCtrl ($scope) {
$scope.$watchCollection('user', function (newVal, oldVal) {
console.log(newVal, oldVal);
});
}
[AngularJS] $scope.$warchCollection的更多相关文章
- 【js类库AngularJs】web前端的mvc框架angularjs之hello world
AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.AngularJS有着诸多特性,最为核 ...
- angularJS--神奇的$scope
我们在使用angularJS时,$scope对于angularJS是非常重要的,它是angularJS的基础,但$scope到底是什么呢?下面进行一些介绍. 1.$scope是一个普通的js对象 2. ...
- JS框架~Angularjs
无意中看到anytao的项目,工作台,使用了Angularjs框架,感觉在前端表现上用户体验比较好,于是就简单看了一下,原来使用很简单,或者说,人家把代码封装的很好,以至于开发人员调用时比较简单,呵呵 ...
- AngularJS 3
AngularJS 源码分析3 本文接着上一篇讲 上一篇地址 回顾 上次说到了rootScope里的$watch方法中的解析监控表达式,即而引出了对parse的分析,今天我们接着这里继续挖代码. $w ...
- 转载:温故而知新 - AngularJS 1.x
原文: http://geek.csdn.net/news/detail/102405 温故而知新 - AngularJS 1.x
- [转][Angularjs]$http.post与$.post
本文转自:https://www.cnblogs.com/wolf-sun/p/6878868.html 摘要 在angularjs发送post请求的时候,确实很困惑,在传递json数据的时候,总会遇 ...
- Spring标签之Bean @Scope
@Bean 的用法 @Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里.添加的bean的id为方法名 定义bean 下面是@Co ...
- AngularJS 从DOM中获取scope
节选官方文档: 原文:https://docs.angularjs.org/guide/scope scope是附加在DOM上,使用了ng-app指令的DOM就是root scope.一般是<h ...
- angular中的scope
angular.element($0).scope() 什么是scope? scope是一个refer to the application model的object.它是一个expression的执 ...
- angualar入门学习-- 作用域$scope
作用域$scope: 是ng执行环境,视图与controller之间的胶水,双向绑定的基础 $scope提供里$watch方法,监听数据模型变化 $scope提供里$apply方法,将数据模型变化更新 ...
随机推荐
- GeneXus手机开发基础配置
最近使用GeneXus15 U3版本做了几个手机端的项目,感觉还不错,开发速度很快,而且想要的功能也都实现了.其中有一些常用的配置和小技巧和大家分享一下. 基础环境要求 如果想开发Android程序, ...
- go chapter 11 初始化 map 数组
// 初始化 map m1 = make(map[string]string) // 初始化 数组 var array3 = []int{9, 10, 11, 12} var a [4]int a[0 ...
- 【伪暴力+智商剪枝】Codeforces Round #489 (Div. 2) D
失踪人口突然回归……orz.题解还是有必要写的,虽然估计只有自己(?自己也不一定看得懂)看得懂. 题目链接:http://codeforces.com/contest/992/problem/D 题目 ...
- 【BZOJ 3307】 3307: 雨天的尾巴 (线段树+树链剖分)
3307: 雨天的尾巴 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 458 Solved: 210 Description N个点,形成一个树状结 ...
- 【贪心】BZOJ3668-[NOI2014]起床困难综合症
[题目大意] 给定n次操作(与,或,异或),在0~m中选择一个数,使这个数经过n次操作后得到的值最大. [思路] 水题orz 枚举这个数每一位的取值是0还是1,然后根据它经过n次操作后的结果判断: ( ...
- bzoj1798 维护序列
Description 老师交给小可可一个维护数列的任务,现在小可可希望你来帮他完成. 有长为N的数列,不妨设为a1,a2,…,aN .有如下三种操作形式: (1)把数列中的一段数全部乘一个值; (2 ...
- JDK源码(1.7) -- java.util.AbstractList<E>
java.util.AbstractList<E> 源码分析(JDK1.7) ------------------------------------------------------- ...
- UESTCACM 每周算法讲堂 延迟标记+bfs dfs搜索入门
http://www.bilibili.com/video/av4163472/ 地址在上面~
- Codeforces Round #245 (Div. 2) B. Balls Game 并查集
B. Balls Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/430/problem ...
- java 随机数种子
引子:需要实现每天随机获得一个礼包,且全服玩家随出来的都是同一个. 实现方案:以当前时间是一年的第几天作为random的种子,取1~礼包总个数范围内的随机值. public static int ge ...