[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方法,将数据模型变化更新 ...
随机推荐
- JAVAEE学习——hibernate03:多表操作详解、级联、关系维护和练习:添加联系人
一.一对多|多对一 1.关系表达 表中的表达 实体中的表达 orm元数据中表达 一对多 <!-- 集合,一对多关系,在配置文件中配置 --> <!-- name属性:集合属性名 co ...
- Wireshark数据抓包教程之Wireshark捕获数据
Wireshark数据抓包教程之Wireshark捕获数据 Wireshark抓包方法 在使用Wireshark捕获以太网数据,可以捕获分析到自己的数据包,也可以去捕获同一局域网内,在知道对方IP地址 ...
- Node.js下的Hello World
Node.js技术现在可谓是如火如荼,前后端都统一为Javascript的体验绝对是受到了很多人的青睐,我都后悔以前没抽时间好好学一学Javascript了. 首先,我来介绍一下Node.js.本人实 ...
- POJ 3228 [并查集]
题目链接:[http://poj.org/problem?id=3228] 题意:给出n个村庄,每个村庄有金矿和仓库,然后给出m条边连接着这个村子.问题是把所有的金矿都移动到仓库里所要经过的路径的最大 ...
- 【BZOJ 4710】 4710: [Jsoi2011]分特产 (容斥原理)
4710: [Jsoi2011]分特产 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 99 Solved: 65 Description JYY 带 ...
- CSS 笔记——列表表格
6. 列表表格 -> 列表 (1)list-style 基本语法 list-style : list-style-image || list-style-position || list-sty ...
- Tsinsen 拉拉队排练
建回文树,然后判断长度奇偶性,统计下来排序即可. 题目链接:http://www.tsinsen.com/ViewGProblem.page?gpid=A1255 By:大奕哥 #include< ...
- UVA11468 Substring --- AC自动机 + 概率DP
UVA11468 Substring 题目描述: 给定一些子串T1...Tn 每次随机选择一个字符(概率会给出) 构造一个长为n的串S,求T1...Tn不是S的子串的概率 直接把T1...Tn建成AC ...
- 【左偏树+贪心】BZOJ1367-[Baltic2004]sequence
[题目大意] 给定一个序列t1,t2,...,tn ,求一个递增序列z1<z2<...<zn , 使得R=|t1−z1|+|t2−z2|+...+|tn−zn| 的值最小.本题中,我 ...
- [POI2012]Squarks
[POI2012]Squarks 题目大意: 设有\(n\)个互不相同的正整数\(\{X_1,X_2,...,X_n\}\),任取两个\(X_i,X_j(i\ne j)\),能算出\(X_i+X_j\ ...