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的更多相关文章

  1. 【js类库AngularJs】web前端的mvc框架angularjs之hello world

    AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前端JS框架,已经被用于Google的多款产品当中.AngularJS有着诸多特性,最为核 ...

  2. angularJS--神奇的$scope

    我们在使用angularJS时,$scope对于angularJS是非常重要的,它是angularJS的基础,但$scope到底是什么呢?下面进行一些介绍. 1.$scope是一个普通的js对象 2. ...

  3. JS框架~Angularjs

    无意中看到anytao的项目,工作台,使用了Angularjs框架,感觉在前端表现上用户体验比较好,于是就简单看了一下,原来使用很简单,或者说,人家把代码封装的很好,以至于开发人员调用时比较简单,呵呵 ...

  4. AngularJS 3

    AngularJS 源码分析3 本文接着上一篇讲 上一篇地址 回顾 上次说到了rootScope里的$watch方法中的解析监控表达式,即而引出了对parse的分析,今天我们接着这里继续挖代码. $w ...

  5. 转载:温故而知新 - AngularJS 1.x

    原文: http://geek.csdn.net/news/detail/102405 温故而知新 - AngularJS 1.x

  6. [转][Angularjs]$http.post与$.post

    本文转自:https://www.cnblogs.com/wolf-sun/p/6878868.html 摘要 在angularjs发送post请求的时候,确实很困惑,在传递json数据的时候,总会遇 ...

  7. Spring标签之Bean @Scope

    @Bean 的用法 @Bean是一个方法级别上的注解,主要用在@Configuration注解的类里,也可以用在@Component注解的类里.添加的bean的id为方法名 定义bean 下面是@Co ...

  8. AngularJS 从DOM中获取scope

    节选官方文档: 原文:https://docs.angularjs.org/guide/scope scope是附加在DOM上,使用了ng-app指令的DOM就是root scope.一般是<h ...

  9. angular中的scope

    angular.element($0).scope() 什么是scope? scope是一个refer to the application model的object.它是一个expression的执 ...

  10. angualar入门学习-- 作用域$scope

    作用域$scope: 是ng执行环境,视图与controller之间的胶水,双向绑定的基础 $scope提供里$watch方法,监听数据模型变化 $scope提供里$apply方法,将数据模型变化更新 ...

随机推荐

  1. 【BZOJ 3106】 3106: [cqoi2013]棋盘游戏 (对抗搜索)

    3106: [cqoi2013]棋盘游戏 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 544  Solved: 233 Description 一个 ...

  2. 「2017 山东一轮集训 Day4」基因

    设置 \(\sqrt{n}\) 个关键点,维护出关键点到每个右端点之间的答案以及Pam的左指针,每次暴力向左插入元素即可,为了去重,还需要记录一下Pam上每个节点在每个关键点为左端点插入到时候到最左边 ...

  3. 「SCOI2015」情报传递

    「SCOI2015」情报传递 题目描述 奈特公司是一个巨大的情报公司,它有着庞大的情报网络.情报网络中共有 \(n\) 名情报员.每名情报员可能有若干名(可能没有)下线,除 \(1\) 名大头目外其余 ...

  4. [CF115E]Linear Kingdom Races

    [CF115E]Linear Kingdom Races 题目大意: 有\(n(n\le10^5)\)个物品,编号为\(1\sim n\).选取第\(i\)个物品需要\(c_i\)的代价.另外有\(m ...

  5. HDU 5646 DZY Loves Partition 数学 二分

    DZY Loves Partition 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5646 Description DZY loves parti ...

  6. hdu 1540 Tunnel Warfare 线段树 单点更新,查询区间长度,区间合并

    Tunnel Warfare Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  7. vscode 插件设置

    VS Code 安装插件 prettier Beautify vscode 首选项 --> 设置 "editor.detectIndentation": false, &qu ...

  8. DLL Injection and Hooking

    DLL Injection and Hooking http://securityxploded.com/dll-injection-and-hooking.php Three Ways to Inj ...

  9. 单端通用ISM频段接收器 Si4313

    Si4313芯片是单端通用ISM频段接收器,工作频率为240-960MHz,可编程接收频率带宽为2.6-260kHz,接收灵敏度为-118dBm,数据速率为0.2-128kb/s,采用FSK.GFSK ...

  10. IPC low/medium/high density 什么意思?

    http://wiki.altium.com/pages/viewpage.action?pageId=3080344 Land Pattern Information Density Level A ...