[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方法,将数据模型变化更新 ...
随机推荐
- Android之 服务(1)
1 简介 服务是Android四大组件之一.不过与Activity不同的是,服务不会直接与用户交互,而是摸摸地在后台运行. 有两种方式来启动系统服务. 一种是调用 Context.startServi ...
- misaka and last order SCU - 4489 (筛法的灵活应用)
Time Limit: 1000 MS Memory Limit: 131072 K Description Misaka Mikoto is a main character of the Anim ...
- Elasticsearch 删除索引下的所有数据
下面是head中操作的截图 #清空索引 POST quality_control/my_type/_delete_by_query?refresh&slices=5&pretty { ...
- BZOJ3669 NOI2014魔法森林
按a从小到大排序,然后按b建图. 每次只需要找1~n中最大的b加当前的a计算答案即可. 这里还有一个小操作就是化边为点,把一条边的边权看做一个点的点权然后多连两条边. By:大奕哥 #include& ...
- 【BIT套主席树】COGS257-动态排名系统
题意同BZOJ1901,多组数据,数据范围也不一样.重新写一遍复习一下. #include<iostream> #include<cstdio> #include<cst ...
- 尝试用Gearman实现分布式处理(PHP)[转]
本文需要你已对Gearman有个大致了解. 顺便再推荐两篇参考文章http://hi.baidu.com/thinkinginlamp/blog/item/ff49972b9e7378f3e6cd40 ...
- redisson实现基于业务的互斥锁
虽然数据库有锁的实现,但是有时候对于数据的操作更需要业务层控制. 这个解决的问题有次面试被问到过,当时不知道怎么解决,乱说一通,今天也算是有个解决方案了 项目中有个需求,就是订单需要经过一层一层的审核 ...
- bzoj 2434 ac自动机
ac自动机中,如果以trie中的节点为节点,(fail[i],i)为边,可以建立一颗树,该树有如下特点:“节点u是节点v的祖先 当且仅当 u代表的字符串是v代表的字符串的一个后缀”.(u代表的字符串是 ...
- HDU 5673 Robot 数学
Robot 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5673 Description There is a robot on the origi ...
- SSM+Maven(教程一):学习SSM框架的前提条件。
准备工作 环境准备 1.配置jdk:http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html Intelij中配置JDK:File- ...