Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated README.md for $watch usage #791

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions a1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
var vm = this;
```

Note: When creating watches in a controller using `controller as`, you can watch the `vm.*` member using the following syntax. (Create watches with caution as they add more load to the digest cycle.)
Note: When creating watches in a controller using `controller as`, you can watch the `vm.*` member using the following syntax (Create watches with caution as they add more load to the digest cycle). Also use a function as the first argument of the watcher, so that you remain in the scope of the controller. In this case vm.title would still be accessible when watcher is hit during digest cycle.

```html
<input ng-model="vm.title"/>
Expand All @@ -414,9 +414,12 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
var vm = this;
vm.title = 'Some Title';

$scope.$watch('vm.title', function(current, original) {
$log.info('vm.title was %s', original);
$log.info('vm.title is now %s', current);
$scope.$watch(function() {
return vm.title;
},
function(current, original) {
$log.info('vm.title was %s', original);
$log.info('vm.title is now %s', current);
});
}
```
Expand Down